1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* webtrees-lib: MyArtJaub library for webtrees |
4
|
|
|
* |
5
|
|
|
* @package MyArtJaub\Webtrees |
6
|
|
|
* @subpackage Certificates |
7
|
|
|
* @author Jonathan Jaubart <[email protected]> |
8
|
|
|
* @copyright Copyright (c) 2009-2016, Jonathan Jaubart |
9
|
|
|
* @license http://www.gnu.org/licenses/gpl.html GNU General Public License, version 3 |
10
|
|
|
*/ |
11
|
|
|
namespace MyArtJaub\Webtrees\Module\Certificates; |
12
|
|
|
|
13
|
|
|
use Fisharebest\Webtrees\Auth; |
14
|
|
|
use Fisharebest\Webtrees\Controller\PageController; |
15
|
|
|
use Fisharebest\Webtrees\Filter; |
16
|
|
|
use Fisharebest\Webtrees\I18N; |
17
|
|
|
use Fisharebest\Webtrees\Module; |
18
|
|
|
use Fisharebest\Webtrees\Module\AbstractModule; |
19
|
|
|
use MyArtJaub\Webtrees\Constants; |
20
|
|
|
use MyArtJaub\Webtrees\Controller\JsonController; |
21
|
|
|
use MyArtJaub\Webtrees\Functions\Functions; |
22
|
|
|
use MyArtJaub\Webtrees\Globals; |
23
|
|
|
use MyArtJaub\Webtrees\ImageBuilder; |
24
|
|
|
use MyArtJaub\Webtrees\Module\Certificates\Model\Certificate; |
25
|
|
|
use MyArtJaub\Webtrees\Module\Certificates\Model\CertificateProviderInterface; |
26
|
|
|
use MyArtJaub\Webtrees\Mvc\Controller\MvcController; |
27
|
|
|
use MyArtJaub\Webtrees\Mvc\View\ViewBag; |
28
|
|
|
use MyArtJaub\Webtrees\Mvc\View\ViewFactory; |
29
|
|
|
use Rhumsaa\Uuid\Uuid; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Controller for Certificate |
33
|
|
|
*/ |
34
|
|
|
class CertificateController extends MvcController |
35
|
|
|
{ |
36
|
|
|
/** |
37
|
|
|
* Certificate Provider |
38
|
|
|
* @var CertificateProviderInterface $provider |
39
|
|
|
*/ |
40
|
|
|
protected $provider; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Constructor for Certificate controller |
44
|
|
|
* @param AbstractModule $module |
45
|
|
|
*/ |
46
|
|
|
public function __construct(AbstractModule $module) { |
47
|
|
|
parent::__construct($module); |
48
|
|
|
|
49
|
|
|
$this->provider = $this->module->getProvider(); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Pages |
55
|
|
|
*/ |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Certificate@index |
59
|
|
|
*/ |
60
|
|
|
public function index() { |
61
|
|
|
$tree = Globals::getTree(); |
62
|
|
|
$controller = new PageController(); |
63
|
|
|
$controller |
64
|
|
|
->setPageTitle(I18N::translate('Certificate')) |
65
|
|
|
->restrictAccess( |
66
|
|
|
$this->module->getSetting('MAJ_SHOW_CERT', Auth::PRIV_HIDE) >= Auth::accessLevel($tree) |
67
|
|
|
); |
68
|
|
|
|
69
|
|
|
$cid = Filter::get('cid'); |
70
|
|
|
|
71
|
|
|
$certificate = null; |
72
|
|
|
if(!empty($cid) && strlen($cid) > 22){ |
73
|
|
|
$certificate = Certificate::getInstance($cid, $tree, null, $this->provider); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
$data = new ViewBag(); |
77
|
|
|
$data->set('title', $controller->getPageTitle()); |
78
|
|
|
|
79
|
|
|
$data->set('has_certif', false); |
80
|
|
|
if($certificate) { |
81
|
|
|
$controller->restrictAccess($certificate->canShow()); |
82
|
|
|
$data->set('title', $certificate->getTitle()); |
83
|
|
|
$data->set('has_certif', true); |
84
|
|
|
$data->set('certificate', $certificate); |
85
|
|
|
|
86
|
|
|
$data->set( |
87
|
|
|
'url_certif_city', |
88
|
|
|
'module.php?mod=' . Constants::MODULE_MAJ_CERTIF_NAME . |
89
|
|
|
'&mod_action=Certificate@listAll' . |
90
|
|
|
'&ged=' . $tree->getNameUrl() . |
91
|
|
|
'&city=' . Functions::encryptToSafeBase64($certificate->getCity()) |
92
|
|
|
); |
93
|
|
|
|
94
|
|
|
$controller->addInlineJavascript(' |
95
|
|
|
jQuery("#certificate-tabs").tabs(); |
96
|
|
|
jQuery("#certificate-tabs").css("visibility", "visible"); |
97
|
|
|
'); |
98
|
|
|
|
99
|
|
|
$data->set('has_linked_indis', false); |
100
|
|
|
$data->set('has_linked_fams', false); |
101
|
|
|
|
102
|
|
|
$linked_indis = $certificate->linkedIndividuals(); |
103
|
|
|
$linked_fams = $certificate->linkedFamilies(); |
104
|
|
|
|
105
|
|
|
if($linked_indis && count($linked_indis) > 0) { |
106
|
|
|
$data->set('has_linked_indis', true); |
107
|
|
|
$data->set('linked_indis', $linked_indis); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
if(!empty($linked_fams)) { |
111
|
|
|
$data->set('has_linked_fams', true); |
112
|
|
|
$data->set('linked_fams', $linked_fams); |
113
|
|
|
} |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
ViewFactory::make('Certificate', $this, $controller, $data)->render(); |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* Certificate@image |
121
|
|
|
*/ |
122
|
|
|
public function image() { |
123
|
|
|
$tree = Globals::getTree(); |
124
|
|
|
$cid = Filter::get('cid'); |
125
|
|
|
$certificate = null; |
126
|
|
|
if(!empty($cid)) $certificate = Certificate::getInstance($cid, $tree, null, $this->provider); |
127
|
|
|
|
128
|
|
|
$imageBuilder = new ImageBuilder($certificate); |
129
|
|
|
|
130
|
|
|
if (!empty(Filter::get('cb'))) { |
131
|
|
|
$imageBuilder->setExpireOffset($imageBuilder->getExpireOffset() * 7); |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
$imageBuilder |
135
|
|
|
->setShowWatermark(Auth::accessLevel($tree) >= $this->module->getSetting('MAJ_SHOW_NO_WATERMARK', Auth::PRIV_HIDE)) |
136
|
|
|
->setFontMaxSize($this->module->getSetting('MAJ_WM_FONT_MAXSIZE', 18)) |
137
|
|
|
->setFontColor($this->module->getSetting('MAJ_WM_FONT_COLOR', '#4D6DF3')) |
138
|
|
|
; |
139
|
|
|
|
140
|
|
|
$imageBuilder->render(); |
141
|
|
|
|
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
/** |
145
|
|
|
* Certificate@listAll |
146
|
|
|
*/ |
147
|
|
|
public function listAll() { |
148
|
|
|
$tree = Globals::getTree(); |
149
|
|
|
$controller = new PageController(); |
150
|
|
|
$controller |
151
|
|
|
->setPageTitle(I18N::translate('Certificates')) |
152
|
|
|
->restrictAccess( |
153
|
|
|
$this->module->getSetting('MAJ_SHOW_CERT', Auth::PRIV_HIDE) >= Auth::accessLevel($tree) |
154
|
|
|
); |
155
|
|
|
|
156
|
|
|
$city = Filter::get('city'); |
157
|
|
|
|
158
|
|
|
if(!empty($city) && strlen($city) > 22){ |
159
|
|
|
$city = Functions::decryptFromSafeBase64($city); |
160
|
|
|
$controller->setPageTitle(I18N::translate('Certificates for %s', $city)); |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
$data = new ViewBag(); |
164
|
|
|
$data->set('title', $controller->getPageTitle()); |
165
|
|
|
$data->set('url_module', $this->module->getName()); |
166
|
|
|
$data->set('url_action', 'Certificate@listAll'); |
167
|
|
|
$data->set('url_ged', $tree->getNameUrl()); |
168
|
|
|
|
169
|
|
|
$data->set('cities', $this->provider->getCitiesList()); |
170
|
|
|
$data->set('selected_city', $city); |
171
|
|
|
|
172
|
|
|
$data->set('has_list', false); |
173
|
|
|
if(!empty($city)) { |
174
|
|
|
$table_id = 'table-certiflist-' . Uuid::uuid4(); |
175
|
|
|
|
176
|
|
|
$certif_list = $this->provider->getCertificatesList($city); |
177
|
|
|
if(!empty($certif_list)) { |
178
|
|
|
$data->set('has_list', true); |
179
|
|
|
$data->set('table_id', $table_id); |
180
|
|
|
$data->set('certificate_list', $certif_list); |
181
|
|
|
|
182
|
|
|
$controller |
183
|
|
|
->addExternalJavascript(WT_JQUERY_DATATABLES_JS_URL) |
184
|
|
|
->addInlineJavascript(' |
185
|
|
|
jQuery.fn.dataTableExt.oSort["text-asc"] = textCompareAsc; |
186
|
|
|
jQuery.fn.dataTableExt.oSort["text-desc"] = textCompareDesc; |
187
|
|
|
|
188
|
|
|
jQuery("#'.$table_id.'").dataTable( { |
189
|
|
|
dom: \'<"H"<"filtersH_' . $table_id . '">T<"dt-clear">pf<"dt-clear">irl>t<"F"pl<"dt-clear"><"filtersF_' . $table_id . '">>\', |
190
|
|
|
'.I18N::datatablesI18N().', |
191
|
|
|
jQueryUI: true, |
192
|
|
|
autoWidth: false, |
193
|
|
|
processing: true, |
194
|
|
|
columns: [ |
195
|
|
|
/* 0-Date */ { type: "num", width: "15%", class: "center" }, |
196
|
|
|
/* 1-Type */ { type: "text", width: "5%", searchable: false, class: "center"}, |
197
|
|
|
/* 2-Certificate */ { type: "text", class: "left" } |
198
|
|
|
], |
199
|
|
|
sorting: [[0,"asc"], [1,"asc"]], |
200
|
|
|
displayLength: 20, |
201
|
|
|
pagingType: "full_numbers" |
202
|
|
|
}); |
203
|
|
|
jQuery(".certificate-list").css("visibility", "visible"); |
204
|
|
|
jQuery(".loading-image").css("display", "none"); |
205
|
|
|
'); |
206
|
|
|
} |
207
|
|
|
} |
208
|
|
|
|
209
|
|
|
ViewFactory::make('CertificatesList', $this, $controller, $data)->render(); |
210
|
|
|
|
211
|
|
|
} |
212
|
|
|
|
213
|
|
|
/** |
214
|
|
|
* Certificate@autocomplete |
215
|
|
|
*/ |
216
|
|
|
public function autocomplete() { |
217
|
|
|
$tree = Globals::getTree(); |
218
|
|
|
$controller = new JsonController(); |
219
|
|
|
|
220
|
|
|
$city = Filter::get('city'); |
221
|
|
|
$contains = Filter::get('term'); |
222
|
|
|
|
223
|
|
|
$controller |
224
|
|
|
->restrictAccess(Auth::isEditor($tree) && !empty($city) && !empty($contains)) |
225
|
|
|
->pageHeader(); |
226
|
|
|
|
227
|
|
|
$listCert = $this->provider->getCertificatesListBeginWith($city, $contains); |
|
|
|
|
228
|
|
|
$controller->encode($listCert); |
229
|
|
|
} |
230
|
|
|
} |
This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.