Skip to content

Commit

Permalink
minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
yild committed Sep 4, 2020
1 parent 8ddcae9 commit a66b580
Show file tree
Hide file tree
Showing 14 changed files with 894 additions and 815 deletions.
2 changes: 1 addition & 1 deletion ajax/record_retention_retention_type_dropdown.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
PluginGdprropaRecord_Retention::showContractInputs($_POST);
break;

case PluginGdprropaRecord_Retention::RETENTION_TYPE_LEGALBASES:
case PluginGdprropaRecord_Retention::RETENTION_TYPE_LEGALBASISACT:
PluginGdprropaRecord_Retention::showLegalBasesInputs($_POST);
break;

Expand Down
1 change: 0 additions & 1 deletion hook.php
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,6 @@ function plugin_gdprropa_install() {
PRIMARY KEY (`id`),
KEY `name` (`name`),
KEY `status` (`status`),
UNIQUE `un_per_record` (`name`, `entities_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
$DB->queryOrDie($query, $DB->error());
Expand Down
2 changes: 1 addition & 1 deletion inc/config.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class PluginGdprropaConfig extends CommonDBTM {
'zapfdingbats'=>'ZapfDingbats'
];

public static function getTypeName($nb = 0) {
public static function getTypeName($nb = 0) {

return _n("Config", "Config", $nb, 'gdprropa');
}
Expand Down
65 changes: 46 additions & 19 deletions inc/createpdf.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ class PluginGdprropaCreatePDF extends PluginGdprropaCreatePDFBase {
'show_is_deleted_header' => 1,
'show_status_in_header' => 1,
'show_full_personaldatacategorylist' => 1,
'show_expired_contracts' => 1,
'show_contracs_types_header_if_empty' => 0,
'show_record_owner' => 1,
'show_assets_owners' => 1,
Expand Down Expand Up @@ -120,7 +121,10 @@ protected function setEntityAndControllerInfo($entity_id) {
$this->entity = new Entity();

$this->controller_info = PluginGdprropaControllerInfo::getFirstControllerInfo($entity_id);
$this->entity->getFromDB($this->controller_info->fields['entities_id']);
if (is_null($this->controller_info)) {
} else {
$this->entity->getFromDB($this->controller_info->fields['entities_id']);
}

}

Expand Down Expand Up @@ -183,6 +187,13 @@ static function showConfigFormElements($config = []) {
echo "</td>";
echo "</tr>";

echo "<tr class='tab_bg_1'>";
echo "<td>" . __("Show expired contracts", 'gdprropa') . "</td>";
echo "<td>";
Dropdown::showYesNo('show_expired_contracts', $config['show_expired_contracts']);
echo "</td>";
echo "</tr>";

echo "<tr class='tab_bg_1'>";
echo "<td>" . __("Show contracts types header if empty list", 'gdprropa') . "</td>";
echo "<td>";
Expand Down Expand Up @@ -363,13 +374,12 @@ static function showForm($report_type, $record_id = -1) {

protected function prepareControllerInfo() {

$controller_name = __("Controller name not set.", 'gdprropa');
$info = "<strong>" . $controller_name . "</strong>";
if (isset($this->controller_info->fields['id'])) {

$controller_name = trim($this->controller_info->fields['controllername']);
if (empty($controller_name)) {
$controller_name = __("Controller name not set.", 'gdprropa');
$info = "<strong>" . $controller_name . "</strong>";
} else {
if (!empty($controller_name)) {

$info = "<ul>";
$info .= "<li>" . __("Name") . ": <strong>" . $controller_name . "</strong>" . "</li>";
Expand Down Expand Up @@ -640,6 +650,10 @@ protected function printHeader() {
protected function printActivitiesList($records) {

if ($records) {

$display_introduced_in = $this->print_options['show_inherited_from'];
$col_width = 42 + 50 * (int)!$display_introduced_in;

$this->writeInternal(
"<h2>" . __("List of processing activities for which entity deals with personal data", 'gdprropa') . "</h2>", [
'linebefore' => 8
Expand All @@ -654,19 +668,23 @@ protected function printActivitiesList($records) {
$tbl = '<table border="1" cellpadding="3" cellspacing="0">' .
'<thead><tr>' .
'<th width="8%" style="background-color:#323232;color:#FFF;text-align:center;"><h3>' . __("No", 'gdprropa') . '</h3></th>' .
'<th width="42%" style="background-color:#323232;color:#FFF;"><h3>' . __("Description of the activity", 'gdprropa') . '</h3></th>' .
'<th width="50%" style="background-color:#323232;color:#FFF;"><h3>' . __("Introduced in", 'gdprropa') . '</h3></th>' .
'</tr></thead><tbody>';
'<th width="' . $col_width . '%" style="background-color:#323232;color:#FFF;"><h3>' . __("Description of the activity", 'gdprropa') . '</h3></th>';
if ($display_introduced_in) {
$tbl .= '<th width="50%" style="background-color:#323232;color:#FFF;"><h3>' . __("Introduced in", 'gdprropa') . '</h3></th>';
}
$tbl .= '</tr></thead><tbody>';

$i = 1;
foreach ($records as $item) {
$entity = new Entity();
$entity->getFromDB($item['entities_id']);
$tbl .= '<tr>' .
'<td width="8%" align="center">' . $i++ . ' </td>' .
'<td width="42%">' . $item['name'] . '</td>' .
'<td width="50%">' . $entity->fields['completename'] . '</td>' .
'</tr>';
'<td width="' . $col_width . '%">' . $item['name'] . '</td>';
if ($display_introduced_in) {
$tbl .= '<td width="50%">' . $entity->fields['completename'] . '</td>';
}
$tbl .= '</tr>';
}
$tbl .= "</tbody></table>";

Expand Down Expand Up @@ -1148,7 +1166,7 @@ protected function printDataRetention(PluginGdprropaRecord $record) {
'</td>';

break;
case PluginGdprropaRecord_Retention::RETENTION_TYPE_LEGALBASES:
case PluginGdprropaRecord_Retention::RETENTION_TYPE_LEGALBASISACT:

$legal_basis = new PluginGdprropaLegalBasisAct();
$legal_basis->getFromDB($item['plugin_gdprropa_legalbasisacts_id']);
Expand Down Expand Up @@ -1192,7 +1210,8 @@ protected function printDataRetention(PluginGdprropaRecord $record) {

protected function printContracts(PluginGdprropaRecord $record, $type, $print_header) {

$iterator = PluginGdprropaRecord_Contract::getContracts($record, $type);
$get_expired = $this->print_options['show_expired_contracts'];
$iterator = PluginGdprropaRecord_Contract::getContracts($record, $type, $get_expired);
$number = count($iterator);

if (!$number && !$this->print_options['show_contracs_types_header_if_empty']) {
Expand Down Expand Up @@ -1221,20 +1240,21 @@ protected function printContracts(PluginGdprropaRecord $record, $type, $print_he
} else {

if ($this->print_options['show_comments']) {
$cols_width = ['15', '25', '15', '20', '25'];
$cols_width = ['13', '23', '13', '18', '10', '23'];
} else {
$cols_width = ['20', '30', '20', '30', '0'];
$cols_width = ['18', '28', '18', '28', '10', '0'];
}

$tbl = '<table border="1" cellpadding="3" cellspacing="0">
<thead><tr>
<th width="' . $cols_width[0] . '%" style="background-color:#AFAFAF;color:#FFF;"><h4>' . __("Supplier") . '</h4></th>
<th width="' . $cols_width[1] . '%" style="background-color:#AFAFAF;color:#FFF;"><h4>' . __("Location") . '</h4></th>
<th width="' . $cols_width[2] . '%" style="background-color:#AFAFAF;color:#FFF;"><h4>' . __("Contact") . '</h4></th>
<th width="' . $cols_width[3] . '%" style="background-color:#AFAFAF;color:#FFF;"><h4>' . __("Contract info", 'gdprropa') . '</h4></th>';
<th width="' . $cols_width[3] . '%" style="background-color:#AFAFAF;color:#FFF;"><h4>' . __("Contract info", 'gdprropa') . '</h4></th>
<th width="' . $cols_width[4] . '%" style="background-color:#AFAFAF;color:#FFF;"><h4>' . __("Expiry", 'gdprropa') . '</h4></th>';
if ($this->print_options['show_comments']) {
$tbl .=
'<th width="' . $cols_width[4] . '%" style="background-color:#AFAFAF;color:#FFF;"><h4>' . __("Comment") . '</h4></th>';
'<th width="' . $cols_width[5] . '%" style="background-color:#AFAFAF;color:#FFF;"><h4>' . __("Comment") . '</h4></th>';
}
$tbl .=
'</tr></thead><tbody>';
Expand Down Expand Up @@ -1283,6 +1303,12 @@ protected function printContracts(PluginGdprropaRecord $record, $type, $print_he
$contract_info .= '<br>' . __("Begin date:", 'gdprropa') . '' . $data['contracts_begin_date'];
}

$expiry = Infocom::getWarrantyExpir($data['contracts_begin_date'], $data['contracts_duration'], $data['contracts_notice'], false);
$expiry_bkg = '#FFFFFF';
if (new DateTime($expiry) < new DateTime()) {
$expiry_bkg = '#FF0000';
}

$comments = '';
if ($data['contracts_comment']) {
$comments = $data['contracts_comment'];
Expand All @@ -1292,10 +1318,11 @@ protected function printContracts(PluginGdprropaRecord $record, $type, $print_he
<td width="' . $cols_width[0] . '%">' . $supplier_name . '</td>
<td width="' . $cols_width[1] . '%">' . $location . '</td>
<td width="' . $cols_width[2] . '%">' . $contact . '</td>
<td width="' . $cols_width[3] . '%">' . $contract_info . '</td>';
<td width="' . $cols_width[3] . '%">' . $contract_info . '</td>
<td width="' . $cols_width[4] . '%" style="background-color:' . $expiry_bkg . '">' . $expiry . '</td>';
if ($this->print_options['show_comments']) {
$tbl .=
'<td width="' . $cols_width[4] . '%">' . nl2br($comments) . '</td>';
'<td width="' . $cols_width[5] . '%">' . nl2br($comments) . '</td>';
}
$tbl .=
'</tr>';
Expand Down
10 changes: 6 additions & 4 deletions inc/record.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ static function getTypeName($nb = 0) {

function showForm($id, $options = []) {

global $CFG_GLPI;

$this->initForm($id, $options);
$this->showFormHeader($options);

Expand Down Expand Up @@ -121,8 +123,8 @@ function showForm($id, $options = []) {
];
Ajax::updateItemOnSelectEvent(
"dropdown_pia_required$rand",
"pia_status_td",
"/plugins/gdprropa/ajax/record_pia_required_dropdown.php",
'pia_status_td',
$CFG_GLPI['root_doc'] . '/plugins/gdprropa/ajax/record_pia_required_dropdown.php',
$params
);

Expand All @@ -141,8 +143,8 @@ function showForm($id, $options = []) {
];
Ajax::updateItemOnSelectEvent(
"dropdown_consent_required$rand",
"consent_storage_tr",
"/plugins/gdprropa/ajax/record_consent_required_dropdown.php",
'consent_storage_tr',
$CFG_GLPI['root_doc'] . '/plugins/gdprropa/ajax/record_consent_required_dropdown.php',
$params
);

Expand Down
39 changes: 27 additions & 12 deletions inc/record_contract.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,11 @@ static function showForRecord(PluginGdprropaRecord $record, $withtemplate = 0) {
$header_end .= "<th>" . __("Name") . "</th>";
$header_end .= "<th>" . __("Supplier") . "</th>";
$header_end .= "<th>" . __("Type") . "</th>";
$header_end .= "<th>" . __("Number") . "</th>";
$header_end .= "<th>" . __("Begin date") . "</th>";
$header_end .= "<th>" . __("Introduced in", 'gdprropa') . "</th>";
$header_end .= "<th>" . __("Comment") . "</th>";
$header_end .= "<th>" . __("Expiry") . "</th>";
$header_end .= "</tr>";

echo $header_begin . $header_top . $header_end;
Expand Down Expand Up @@ -267,6 +269,7 @@ static function showForRecord(PluginGdprropaRecord $record, $withtemplate = 0) {

echo "<td class='center'>" . $out . "</td>";
echo "<td class='center'>" . Dropdown::getDropdownName('glpi_contracttypes', $data['contracttypes_id']) . "</td>";
echo "<td>" . $data['num'] . "</td>";
echo "<td class='left'>" . $data['begin_date'] . "</td>";

echo "<td class='left'>";
Expand All @@ -277,6 +280,12 @@ static function showForRecord(PluginGdprropaRecord $record, $withtemplate = 0) {

echo "<td class='left'>" . $data['comment'] . "</td>";

echo "<td>";
if ($data["notice"] > 0) {
echo Infocom::getWarrantyExpir($data['begin_date'], $data['duration'], $data['notice'], true);
}
echo "</td>";

echo "</tr>";
}

Expand Down Expand Up @@ -414,7 +423,6 @@ static function getContractsDropdown($options = []) {
ORDER BY `glpi_entities`.`completename`,
`glpi_contracts`.`name` ASC,
`glpi_contracts`.`begin_date` DESC";

$result = $DB->query($query);

$group = '';
Expand Down Expand Up @@ -456,7 +464,7 @@ static function getContractsDropdown($options = []) {
]);
}

static function getContracts($record, $type = null) {
static function getContracts($record, $type = null, $get_expired = false) {

global $DB;

Expand Down Expand Up @@ -490,13 +498,13 @@ static function getContracts($record, $type = null) {

}

$iterator = $DB->request([
'SELECT' => [
$query['SELECT'] = [
'glpi_contracts.name AS contracts_name',
'glpi_contracts.num AS contracts_num',
'glpi_contracts.begin_date AS contracts_begin_date',
'glpi_contracts.duration AS contracts_duration',
'glpi_contracts.periodicity AS contracts_periodicity',
'glpi_contracts.notice AS contracts_notice',
'glpi_contracts.comment AS contracts_comment',
'glpi_contracts.contracttypes_id AS contracttypes_id',
'glpi_suppliers.name AS suppliers_name',
Expand All @@ -512,9 +520,9 @@ static function getContracts($record, $type = null) {
'glpi_suppliers.comment AS suppliers_comment',
'glpi_contracttypes.name AS contractypes_name',
'glpi_contracttypes.comment AS contractypes_comment',
],
'FROM' => ['glpi_contracts'],
'LEFT JOIN' => [
];
$query['FROM'] = ['glpi_contracts'];
$query['LEFT JOIN'] = [
'glpi_plugin_gdprropa_records_contracts' => [
'FKEY' => [
'glpi_contracts' => 'id',
Expand All @@ -538,13 +546,20 @@ static function getContracts($record, $type = null) {
'glpi_contracts' => 'contracttypes_id'
]
],
],
'WHERE' => [
];
$query['WHERE'] = [
'glpi_plugin_gdprropa_records_contracts.plugin_gdprropa_records_id' => $record->fields['id'],
'glpi_contracttypes.id' => $contract_type,
'glpi_contracts.is_deleted' => 0
],
]);
'glpi_contracts.is_deleted' => 0,
];

if (!$get_expired) {
$query['WHERE'][] = "DATEDIFF(ADDDATE(`glpi_contracts`.`begin_date`, INTERVAL `glpi_contracts`.`duration` MONTH), CURDATE()) > '0' OR
`glpi_contracts`.`begin_date` IS NULL OR (`glpi_contracts`.`duration` = 0 AND
DATEDIFF(`glpi_contracts`.`begin_date`, CURDATE() ) < '0' ) OR
`glpi_contracts`.`renewal` = 1";
}
$iterator = $DB->request($query);

return $iterator;
}
Expand Down
Loading

0 comments on commit a66b580

Please sign in to comment.