From 79e665eda12494d03b2f3523155fdc54286e0078 Mon Sep 17 00:00:00 2001 From: Charlene Auger Date: Fri, 5 May 2023 16:13:46 +0200 Subject: [PATCH] Update classes --- inc/action.class.php | 228 ++++++++++++++-------- inc/config.class.php | 426 ++++++++++++++++++++++-------------------- inc/history.class.php | 43 +++-- inc/profile.class.php | 96 +++++----- 4 files changed, 457 insertions(+), 336 deletions(-) diff --git a/inc/action.class.php b/inc/action.class.php index a2d6938..76abf19 100644 --- a/inc/action.class.php +++ b/inc/action.class.php @@ -1,19 +1,38 @@ . + * --------------------------------------------------------------------- */ class PluginGdprcomplianceAction extends CommonDBTM { - /** + /** * @param int $nb * * @return translated @@ -43,78 +62,84 @@ static function install($migration) { * @return arrray of information **/ static function cronInfo($name) { - - switch ($name) { - case 'CleanUsers' : - return array('description' => __('Clean inactive Users', 'gdprcompliance')); + switch ($name) { + case 'CleanUsers' : + return array('description' => __('Clean inactive Users', 'gdprcompliance')); + } + return []; } - return []; - } - + + /** + * cronCleanUsers + * + * @param mixed $task + * @return void + */ static function cronCleanUsers($task){ global $DB; $cronTask = new CronTask(); + if ($cronTask->getFromDBbyName("PluginGdprcomplianceAction", "CleanUsers")) { - if ($cronTask->fields["state"] == CronTask::STATE_DISABLE) { - return 0; - } + if ($cronTask->fields["state"] == CronTask::STATE_DISABLE) { + return 0; + } } else { - return 0; + return 0; } + $cron_status = 0; $query = "SELECT * FROM glpi_plugin_gdprcompliance_configs"; $result_glpi = $DB->query($query); $config = []; + if ($DB->numrows($result_glpi) > 0) { - $i = 0; - while ($data = $DB->fetchArray($result_glpi)) { - $config['active'] = $data['active']; - $config['mode'] = $data['mode']; - if (!is_null($data['change'])) { - $changes = explode(',', $data['change']); - } - foreach ($changes as $key => $change) { - if ($change == "") { - continue; - } - $test = explode(';', $change); - if (count($test) > 1) { - $config['changes'][$test[0]]['value'] = 2; - $config['changes'][$test[0]]['change'] = $test[1]; - } else { - $config['changes'][$change]['value'] = 1; - $config['changes'][$change]['change'] = ""; - } - } - $i++; - } + while ($data = $DB->fetchArray($result_glpi)) { + $config['active'] = $data['active']; + $config['mode'] = $data['mode']; + + $changes = []; + + if (!is_null($data['change'])) $changes = json_decode($data['change']); + + foreach ($changes as $key => $change) { + if($change == 999) { + $config['changes'][$key]['value'] = 999; + } elseif($change == 1) { + $config['changes'][$key]['value'] = 1; + } else { + $config['changes'][$key]['value'] = 2; + $config['changes'][$key]['change'] = $change; + } + } + } } $listUsers = []; if ($config['active']) { + $User = new User(); - $query = "SELECT * FROM glpi_users"; - $users_result = $DB->query($query); + $users = $User->find(["is_active" => 0, "is_deleted" => 0]); - while ($user = $DB->fetchArray($users_result)) { - if (!$user['is_active'] && !$user['is_deleted']) { - $listUsers[] = self::changeUserData($user, $config['changes']); - } + foreach($users as $id => $values) { + $listUsers[] = self::changeUserData($values, $config['changes']); } } + $sucess = 0; $errors = 0; foreach ($listUsers as $key => $user) { try { if (!$config['mode']) { - self::cleanUsers($user); + self::cleanUsers($user["user"]); + self::cleanUserEmail($user["mail"]); } else { - self::removeUsers($user); + self::removeUsers($user["user"]); } + $sucess += 1; } catch(Exception $e){ $errors += 1; @@ -126,51 +151,96 @@ static function cronCleanUsers($task){ return $cron_status; } + + /** + * changeUserData + * + * @param mixed $user + * @param mixed $changes + * @return void + */ + static private function changeUserData($user, $changes = []) { + $usersToUpdate['user'] = $user; + $usersToUpdate['mail'] = []; - static private function changeUserData($user, $changes = []){ - $exclude = ['id', 'name' => 1, 'locations_id' => 1,'use_mode' => 1,'is_active' => 1,'auths_id' => 1,'authtype' => 1,'is_deleted' => 1,'profiles_id' => 1,'entities_id' => 1,'usertitles_id' => 1,'usercategories_id' => 1,'is_deleted_ldap' => 1,'groups_id' => 1,'users_id_supervisor' => 1,'password' => 1]; foreach ($user as $key => $value) { - - if (is_int($key)) { - unset($user[$key]); - continue; - } - if (array_key_exists($key, $changes)) { - if ($changes[$key]['value'] == 1) { - # code... - } elseif ($changes[$key]['value'] == 2) { - $user[$key] = $changes[$key]['change']; - } - } else { - if (in_array($key, $exclude)) { - if ($key != 'id') { - unset($user[$key]); - } - } else { - $user[$key] = ""; + if ($changes[$key]['value'] == 2) { + $usersToUpdate['user'][$key] = $changes[$key]['change']; + } elseif($changes[$key]['value'] == 999) { + $usersToUpdate['user'][$key] = null; } } } - return $user; + // User email process + if($changes["email"]["value"] == 2) { + $usersToUpdate["mail"]["update"] = [ + "users_id" => $user["id"], + "email" => $changes["email"]["change"] + ]; + } elseif($changes["email"]["value"] == 999) { + $usersToUpdate["mail"]["delete"] = [ + "users_id" => $user["id"] + ]; + } + return $usersToUpdate; } - + + /** + * cleanUsers + * + * @param mixed $user + * @return void + */ static private function cleanUsers($user){ - global $DB; - $nUser = new User(); $user['is_deleted'] = true; $nUser->update($user); } - + + /** + * cleanUserEmail + * + * @param mixed $userEmail + * @return void + */ + static function cleanUserEmail($userEmail) { + $UserEmail = new UserEmail(); + + if(isset($userEmail["update"])) { + $userEmails = $UserEmail->find(["users_id" => $userEmail["update"]["users_id"]]); + // increment and concat to email for field unicity + $index = 0; + + foreach($userEmails as $id => $mail) { + $mail["email"] = $userEmail["update"]["email"].$index; + $UserEmail->update($mail); + $index++; + } + } elseif($userEmail["delete"]) { + $userEmails = $UserEmail->find(["users_id" => $userEmail["delete"]["users_id"]]); + foreach($userEmails as $id => $mail) { + $mail["email"] = $userEmail["update"]["email"]; + $UserEmail->delete($mail); + } + } + } + + /** + * removeUsers + * + * @param mixed $user + * @return void + */ static private function removeUsers($user){ - global $DB; - - $query = "DELETE FROM glpi_users WHERE id = " . $user['id']; + $nUser = new User(); + $userToPurge = [ + "id" => $user["id"] + ]; - $DB->query($query); + $nUser->delete($userToPurge, 1); } } \ No newline at end of file diff --git a/inc/config.class.php b/inc/config.class.php index d4f8cea..089ef00 100644 --- a/inc/config.class.php +++ b/inc/config.class.php @@ -1,14 +1,33 @@ . + * --------------------------------------------------------------------- */ /** @@ -21,6 +40,43 @@ class PluginGdprcomplianceConfig extends CommonDBTM { */ static $rightname = "plugin_gdprcompliance_config"; + private $allowFields = [ + 'name', + 'password_last_update', + 'phone', + 'phone2', + 'mobile', + 'realname', + 'firstname', + 'locations_id', + 'comment', + 'authtype', + 'last_login', + 'date_mod', + 'date_sync', + 'usertitles_id', + 'usercategories_id', + 'password_forget_token_date', + 'user_dn', + 'registration_number', + 'personal_token', + 'personal_token_date', + 'api_token_date', + 'api_token', + 'cookie_token_date', + 'picture', + 'begin_date', + 'end_date', + 'date_creation', + 'users_id_supervisor', + 'timezone', + 'email' + ]; + + private $textField = [ + "char", "varchar", "text", "longtext" + ]; + /** * @param int $nb * @@ -29,9 +85,13 @@ class PluginGdprcomplianceConfig extends CommonDBTM { static function getTypeName($nb = 0) { return __("GDPR Configuration", 'gdprcompliance'); } - + + /** + * getMenuContent + * + * @return void + */ static function getMenuContent() { - $menu = parent::getMenuContent(); //Menu entry in config $menu['title'] = self::getTypeName(2); @@ -41,13 +101,13 @@ static function getMenuContent() { return $menu; } - + + /** + * showMenu + * + * @return void + */ function showMenu(){ - global $DB, $CFG_GLPI; - - $user = new User(); - $assos = $user->rawSearchOptions(); - echo "
"; if (Session::haveRight("plugin_gdprcompliance_config", READ) || Session::haveRight("plugin_gdprcompliance_config", UPDATE) || @@ -55,14 +115,14 @@ function showMenu(){ echo ""; echo ""; - echo ""; + echo ""; echo ""; if (Session::haveRight("plugin_gdprcompliance_config", READ) || Session::haveRight("plugin_gdprcompliance_config", UPDATE)) { echo ""; - echo ""; + echo ""; echo ""; echo ""; - echo ""; + echo ""; echo ""; } if (Session::haveRight("plugin_gdprcompliance_history", READ)) { @@ -84,7 +144,6 @@ function showMenu(){ * @return bool */ function showForm($ID, $options = []) { - global $DB; $mode = [ @@ -95,30 +154,11 @@ function showForm($ID, $options = []) { $query = "SELECT * FROM glpi_plugin_gdprcompliance_configs"; $result_glpi = $DB->query($query); $saved = []; + if ($DB->numrows($result_glpi) > 0) { - $i = 0; while ($data = $DB->fetchArray($result_glpi)) { - if (!is_null($data['change'])) { - $changes = explode(',', $data['change']); - } else { - $changes = []; - } - foreach ($changes as $key => $change) { - if ($change == "") { - continue; - } - $test = explode(';', $change); - if (count($test) > 1) { - $saved[$test[0]]['value'] = 2; - $saved[$test[0]]['change'] = $test[1]; - } else { - $saved[$change]['value'] = 1; - $saved[$change]['change'] = ""; - } - } $saved['active'] = $data['active']; $saved['mode'] = $data['mode']; - $i++; } } @@ -126,7 +166,7 @@ function showForm($ID, $options = []) { $this->showFormHeader($options); echo ""; - echo ""; @@ -140,243 +180,223 @@ function showForm($ID, $options = []) { return true; } - + + /** + * showConfigData + * + * @param mixed $ID + * @param mixed $options + * @return void + */ function showConfigData($ID, $options = []){ global $DB; - $user = new User(); - $assos = $user->rawSearchOptions(); - $assoc = []; - - foreach ($assos as $key => $value) { - if (array_key_exists('field', $value) && array_key_exists('name', $value)) { - $assoc[$value['field']] = $value['name']; - } - } - - //var_dump("
", $assoc , "
"); - - $query = "SELECT `COLUMN_NAME` FROM `INFORMATION_SCHEMA`.`COLUMNS` WHERE `TABLE_SCHEMA`=Database() AND `TABLE_NAME`='" . 'glpi_users' . "'"; + $query = "SELECT `COLUMN_NAME`, `DATA_TYPE` FROM `INFORMATION_SCHEMA`.`COLUMNS` WHERE `TABLE_SCHEMA`=Database() AND `TABLE_NAME`='glpi_users'"; $result_glpi = $DB->query($query); - $snmpLinks = []; - - $exclud = ['id', 'entities_id', 'password', 'is_global', 'is_template', 'groups_id', 'users_id', 'is_dynamic', 'is_active', 'is_deleted', 'password_forget_token']; + $userColumns = []; if ($DB->numrows($result_glpi) > 0) { - $i = 0; while ($data = $DB->fetchArray($result_glpi)) { - if (!in_array($data['COLUMN_NAME'], $exclud)) { - $snmpLinks[$data['COLUMN_NAME']] = $data['COLUMN_NAME']; - $i++; + if (in_array($data['COLUMN_NAME'], $this->allowFields)) { + $userColumns[$data['COLUMN_NAME']]['COLUMN_NAME'] = $data['COLUMN_NAME']; + $userColumns[$data['COLUMN_NAME']]['COLUMN_TYPE'] = $data['DATA_TYPE']; } } + $userColumns['email']['COLUMN_NAME'] = 'email'; + $userColumns['email']['COLUMN_TYPE'] = 'varchar'; } $query = "SELECT * FROM glpi_plugin_gdprcompliance_configs"; $result_glpi = $DB->query($query); $saved = []; + if ($DB->numrows($result_glpi) > 0) { - $i = 0; while ($data = $DB->fetchArray($result_glpi)) { - if (!is_null($data['change'])) { - $changes = explode(',', $data['change']); - } else { - $changes = []; - } + $changes = []; + + if(!is_null($data['change'])) $changes = json_decode($data['change']); + foreach ($changes as $key => $change) { - if ($change == "") { - continue; - } - $test = explode(';', $change); - if (count($test) > 1) { - $saved[$test[0]]['value'] = 2; - $saved[$test[0]]['change'] = $test[1]; + if($change == 999) { + $saved[$key]['value'] = 0; + $saved[$key]['change'] = null; + } elseif($change == 1) { + $saved[$key]['value'] = 1; + $saved[$key]['change'] = null; } else { - $saved[$change]['value'] = 1; - $saved[$change]['change'] = ""; + $saved[$key]['value'] = 2; + $saved[$key]['change'] = $change; } } $saved['active'] = $data['active']; $saved['mode'] = $data['mode']; - $i++; } } - $this->initForm($ID, $options); $state = $this->getState(); $this->showFormHeader(['formtitle' => false]); echo ""; - echo ""; + echo ""; echo ""; echo ""; echo ""; - foreach ($snmpLinks as $key => $value) { + foreach ($userColumns as $key => $value) { + $presetValue = ""; + if(isset($saved[$value['COLUMN_NAME']])) $presetValue = $saved[$value['COLUMN_NAME']]['change']; + echo ""; echo ""; - echo ""; echo ""; + echo ""; + echo ""; } else { - echo ""; + Dropdown::showFromArray($value['COLUMN_NAME'], [__('Forget', 'gdprcompliance'), __('Keep', 'gdprcompliance')], ['value' => array_key_exists($value['COLUMN_NAME'], $saved) ? $saved[$value['COLUMN_NAME']]['value'] : 0]); + echo ""; + echo ""; + echo ""; } - echo ""; - echo ""; + } $this->showFormButtons($options); return true; } - + + /** + * updateConfig + * + * @param mixed $idConfig + * @param mixed $post + * @return void + */ public function updateConfig($idConfig, $post) { global $DB; - if (array_key_exists('active', $post) && array_key_exists('mode', $post)) { - $active = $post['active']; $mode = $post['mode']; $query = "UPDATE glpi_plugin_gdprcompliance_configs SET active = $active, mode = $mode WHERE id = $idConfig"; } else { - $changes = ""; + $changes = []; + foreach ($post as $key => $value) { - if (substr( $key, 0, 7 ) === "change_") { - continue; - } - if ($value == 2) { - $changes .= $key . ';' . $post['change_' . $key] . ','; - } elseif ($value == 1) { - $changes .= $key . ','; + if (in_array($key, $this->allowFields) && $value == 2) { + $changes[$key] = addslashes($post['change_'.$key]); + } elseif (in_array($key, $this->allowFields) && $value == 1) { + $changes[$key] = 1; + } elseif(in_array($key, $this->allowFields) && $value == 0) { + $changes[$key] = 999; } } + + $changes = json_encode($changes); + $query = "UPDATE glpi_plugin_gdprcompliance_configs SET `change` = '$changes' WHERE id = $idConfig"; } $DB->query($query); } - + + /** + * getState + * + * @return void + */ private function getState() { - $allState = []; - $state = new State(); - $states = $state->find(); - foreach($states as $list) { - $allState[$list['id']] = $list['name']; - } - - return $allState; - } + $allState = []; + $state = new State(); + $states = $state->find(); + + foreach($states as $list) { + $allState[$list['id']] = $list['name']; + } + return $allState; + } + + /** + * getSearchOptions + * + * @return void + */ public function getSearchOptions() { - $tab = array(); - - return $tab; + $tab = array(); + + return $tab; } - + + /** + * install + * + * @param mixed $mig + * @return void + */ public function install(Migration $mig) { - return true; - } - + return true; + } + + /** + * uninstall + * + * @return void + */ public function uninstall() { - return true; + return true; } - + + /** + * translateField + * + * @param mixed $value + * @return void + */ static function translateField($value) { $translation = [ - 'name' => __('Login', 'gdprcompliance'), - 'password_last_update' => __('Password last update', 'gdprcompliance'), - 'phone' => __('Phone', 'gdprcompliance'), - 'phone2' => __('Phone 2', 'gdprcompliance'), - 'mobile' => __('Mobile', 'gdprcompliance'), - 'realname' => __('Lastname', 'gdprcompliance'), - 'firstname' => __('Firstname', 'gdprcompliance'), - 'locations_id' => __('Locations', 'gdprcompliance'), - 'language' => __('Language', 'gdprcompliance'), - 'use_mode' => __('Use mode', 'gdprcompliance'), - 'list_limit' => __('List limit', 'gdprcompliance'), - 'comment' => __('Comment', 'gdprcompliance'), - 'auths_id' => __('Auth', 'gdprcompliance'), - 'authtype' => __('Auth type', 'gdprcompliance'), - 'last_login' => __('Last login', 'gdprcompliance'), - 'date_mod' => __('Date modification', 'gdprcompliance'), - 'date_sync' => __('Date synchronisation', 'gdprcompliance'), - 'profiles_id' => __('Profiles', 'gdprcompliance'), - 'usertitles_id' => __('user titles', 'gdprcompliance'), - 'usercategories_id' => __('User categories', 'gdprcompliance'), - 'date_format' => __('Date format', 'gdprcompliance'), - 'number_format' => __('Number format', 'gdprcompliance'), - 'names_format' => __('Name format', 'gdprcompliance'), - 'csv_delimiter' => __('csv delimiter', 'gdprcompliance'), - 'is_ids_visible' => __('ids is visible', 'gdprcompliance'), - 'use_flat_dropdowntree' => __('Use flat dropdowntree', 'gdprcompliance'), - 'show_jobs_at_login' => __('Show jobs at login', 'gdprcompliance'), - 'priority_1' => __('Priority 1', 'gdprcompliance'), - 'priority_2' => __('Priority 2', 'gdprcompliance'), - 'priority_3' => __('Priority 3', 'gdprcompliance'), - 'priority_4' => __('Priority 4', 'gdprcompliance'), - 'priority_5' => __('Priority 5', 'gdprcompliance'), - 'priority_6' => __('Priority 6', 'gdprcompliance'), - 'followup_private' => __('Followup private', 'gdprcompliance'), - 'task_private' => __('Task private', 'gdprcompliance'), - 'default_requesttypes_id' => __('Default request types', 'gdprcompliance'), - 'password_forget_token_date' => __('password forget token date', 'gdprcompliance'), + 'name' => __('Login'), + 'password_last_update' => __('Last date of password update', 'gdprcompliance'), + 'phone' => __('Phone'), + 'phone2' => __('Phone 2'), + 'mobile' => __('Mobile phone'), + 'realname' => __('Surname'), + 'firstname' => __('First name'), + 'locations_id' => __('Location'), + 'comment' => __('Comment'), + 'authtype' => __('Authentication type'), + 'last_login' => __('Last login'), + 'date_mod' => __('Last update'), + 'date_sync' => __('Last synchronization'), + 'usertitles_id' => __('Title'), + 'usercategories_id' => __('Category'), + 'password_forget_token_date' => __('Last date of forget password token generation', 'gdprcompliance'), 'user_dn' => __('User DN', 'gdprcompliance'), - 'registration_number' => __('Registration number', 'gdprcompliance'), - 'show_count_on_tabs' => __('Show count on tabs', 'gdprcompliance'), - 'refresh_views' => __('Refresh views', 'gdprcompliance'), - 'set_default_tech' => __('Set default tech', 'gdprcompliance'), - 'personal_token_date' => __('Personal token date', 'gdprcompliance'), - 'api_token_date' => __('API token date', 'gdprcompliance'), - 'cookie_token_date' => __('Cookie token Date', 'gdprcompliance'), - 'display_count_on_home' => __('Display count on Home', 'gdprcompliance'), - 'notification_to_myself' => __('Notification to myself', 'gdprcompliance'), - 'duedateok_color' => __('Due date OK color', 'gdprcompliance'), - 'duedatewarning_color' => __('Due date Warning color', 'gdprcompliance'), - 'duedatecritical_color' => __('Due date Critical color', 'gdprcompliance'), - 'duedatewarning_less' => __('Due date warning less', 'gdprcompliance'), - 'duedatecritical_less' => __('Due date critical less', 'gdprcompliance'), - 'duedatewarning_unit' => __('Due date warning Unit', 'gdprcompliance'), - 'duedatecritical_unit' => __('Due date critical Unit', 'gdprcompliance'), - 'display_options' => __('Display options', 'gdprcompliance'), - 'is_deleted_ldap' => __('Is deleted LDAP', 'gdprcompliance'), - 'pdffont' => __('PDF font', 'gdprcompliance'), - 'picture' => __('Picture', 'gdprcompliance'), - 'begin_date' => __('Begin date', 'gdprcompliance'), - 'end_date' => __('End Date', 'gdprcompliance'), - 'keep_devices_when_purging_item' => __('Keep devices when purging item', 'gdprcompliance'), - 'privatebookmarkorder' => __('Private bookmark order', 'gdprcompliance'), - 'backcreated' => __('back created', 'gdprcompliance'), - 'task_state' => __('task state', 'gdprcompliance'), - 'layout' => __('layout', 'gdprcompliance'), - 'palette' => __('palette', 'gdprcompliance'), - 'set_default_requester' => __('set default requester', 'gdprcompliance'), - 'lock_autolock_mode' => __('lock autolock mode', 'gdprcompliance'), - 'lock_directunlock_notification' => __('lock direct unlock notification', 'gdprcompliance'), - 'date_creation' => __('date creation', 'gdprcompliance'), - 'highcontrast_css' => __('high contrast CSS', 'gdprcompliance'), - 'plannings' => __('plannings', 'gdprcompliance'), - 'sync_field' => __('synchronisation field', 'gdprcompliance'), - 'users_id_supervisor' => __('supervivor', 'gdprcompliance'), - 'timezone' => __('Timezone', 'gdprcompliance'), - 'default_dashboard_central' => __('Default dashboard central', 'gdprcompliance'), - 'default_dashboard_assets' => __('Default dashboard assets', 'gdprcompliance'), - 'default_dashboard_helpdesk' => __('Default dashboard helpdesk', 'gdprcompliance'), - 'default_dashboard_mini_ticket' => __('Default dashboard mini ticket', 'gdprcompliance'), - 'access_zoom_level' => __('access zoom level', 'gdprcompliance'), - 'access_font' => __('Access font', 'gdprcompliance'), - 'access_shortcuts' => __('Access shortcuts', 'gdprcompliance'), - 'access_custom_shortcuts' => __('Accesss custom shortcut', 'gdprcompliance'), + 'registration_number' => __('Administrative number'), + 'personal_token' => __('Personal token'), + 'personal_token_date' => __('Last date of personal token generation', 'gdprcompliance'), + 'api_token_date' => __('Last date of API token generation', 'gdprcompliance'), + 'api_token' => __('API token'), + 'cookie_token_date' => __('Last date of cookie token generation', 'gdprcompliance'), + 'picture' => __('Picture'), + 'begin_date' => __('Valid since'), + 'end_date' => __('Valid until'), + 'date_creation' => __('Creation date'), + 'users_id_supervisor' => __('Responsible'), + 'timezone' => __('Timezone'), + 'email' => __('Email') ]; return array_key_exists($value, $translation) ? $translation[$value] : $value; diff --git a/inc/history.class.php b/inc/history.class.php index 3616732..edf30bd 100644 --- a/inc/history.class.php +++ b/inc/history.class.php @@ -1,18 +1,37 @@ . + * --------------------------------------------------------------------- */ class PluginGdprcomplianceHistory extends CommonDBTM { - static $rightname = "plugin_gdprcompliance_config"; + static $rightname = "plugin_gdprcompliance_history"; /** * @param int $nb @@ -20,7 +39,7 @@ class PluginGdprcomplianceHistory extends CommonDBTM { * @return string|translated */ static function getTypeName($nb = 0) { - return __("IHistorique", 'gdprcompliance'); + return __("History", 'gdprcompliance'); } public static function showHistory(){ @@ -35,7 +54,7 @@ public static function showHistory(){ echo "
" . __("GDPR Plugin", 'gdprcompliance') . "" . __("GDPR Compliance", 'gdprcompliance') . "
" . __("Configuration", 'gdprcompliance') . "" . __("Setup") . "
" . __("Data configuration", 'gdprcompliance') . "" . __("User data configuration", 'gdprcompliance') . "
" . __('Active automitic action', 'gdprcompliance') . " "; + echo " " . __('Active automatic action', 'gdprcompliance') . " "; Dropdown::showYesNo("active", $saved['active']); echo "
" . __("Data", 'gdprcompliance') . "" . __("User data", 'gdprcompliance') . "" . __("Action", 'gdprcompliance') . "" . __("Replace", 'gdprcompliance') . "
"; - //echo array_key_exists($value, $assoc) ? $assoc[$value] : $value; - echo self::translateField($value); - echo ""; - Dropdown::showFromArray($value, [__('Forgot', 'gdprcompliance'), __('Keep', 'gdprcompliance'), __('Change', 'gdprcompliance')], ['value' => array_key_exists($value, $saved) ? $saved[$value]['value'] : 0]); + echo self::translateField($value['COLUMN_NAME']); echo ""; - if (array_key_exists($value, $saved)) { - echo ""; + + if(in_array($value['COLUMN_TYPE'], $this->textField)) { + Dropdown::showFromArray($key, [__('Forget', 'gdprcompliance'), __('Keep', 'gdprcompliance'), __('Change', 'gdprcompliance')], ['value' => array_key_exists($value['COLUMN_NAME'], $saved) ? $saved[$value['COLUMN_NAME']]['value'] : 0]); + echo ""; + echo ""; + echo "
"; echo ""; echo ""; - echo ""; + echo ""; echo ""; while ($data = $DB->fetchArray($result_glpi)){ echo ""; diff --git a/inc/profile.class.php b/inc/profile.class.php index b127a8d..b12c21b 100644 --- a/inc/profile.class.php +++ b/inc/profile.class.php @@ -1,14 +1,33 @@ . + * --------------------------------------------------------------------- */ if (!defined('GLPI_ROOT')) { @@ -21,20 +40,17 @@ class PluginGdprcomplianceProfile extends Profile static $rightname = "profile"; static $all_profile_rights = array( - 'plugin_gdprcompliance_config', + 'plugin_gdprcompliance_config', ); - public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) - { - + public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) { if ($item->getType() == 'Profile') { return PluginGdprcomplianceConfig::getTypeName(0); } return ''; } - static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0) - { + static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0) { $_profile = new self(); if ($item->getType() == 'Profile') { $id = $item->getID(); @@ -45,21 +61,18 @@ static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtem return true; } - static function install(Migration $migration) - { + static function install(Migration $migration) { // Create my right access self::addRight(false, 5); } - static function uninstall() - { + static function uninstall() { // Remove all profiles self::removeAllRight(); return true; } - static function removeAllRight() - { + static function removeAllRight() { $_profile = new ProfileRight(); foreach ($_profile->find("`name` LIKE 'plugin_gdprcompliance_%'") as $data) { $_profile->delete($data); @@ -72,11 +85,10 @@ static function removeAllRight() * @param $profiles_id * @param $right_value */ - static function addRight($profiles_id, $right_value) - { + static function addRight($profiles_id, $right_value) { $_profile = new ProfileRight(); foreach (self::$all_profile_rights as $profile_name) { - if (!$_profile->find("`profiles_id` = $profiles_id and `name` = '$profile_name'")) { + if (!$_profile->find(["profiles_id" => $profiles_id, "name" => $profile_name])) { $right['profiles_id'] = $profiles_id ?: $_SESSION['glpiactiveprofile']['id']; $right['name'] = $profile_name; $right['rights'] = $right_value; @@ -94,8 +106,7 @@ static function addRight($profiles_id, $right_value) * @param bool|true $closeform * @return bool */ - public function showForm($profiles_id = 0, $openform = true, $closeform = true) - { + public function showForm($profiles_id = 0, $openform = true, $closeform = true) { $profile = new Profile(); $canedit = Session::haveRightsOr(self::$rightname, array(READ, UPDATE)); @@ -108,9 +119,10 @@ public function showForm($profiles_id = 0, $openform = true, $closeform = true) $config_right = $this->getAllRights(); $profile->displayRightsChoiceMatrix($config_right, array( - 'canedit' => $canedit, - 'default_class' => 'tab_bg_2', - 'title' => __s('General'))); + 'canedit' => $canedit, + 'default_class' => 'tab_bg_2', + 'title' => __s('General')) + ); if ($canedit && $closeform) { echo "
"; @@ -119,6 +131,7 @@ public function showForm($profiles_id = 0, $openform = true, $closeform = true) echo "
"; Html::closeForm(); } + echo ""; $this->showLegend(); @@ -126,22 +139,21 @@ public function showForm($profiles_id = 0, $openform = true, $closeform = true) return true; } - static function getAllRights() - { + static function getAllRights() { $rights = array( - array( - 'itemtype' => 'PluginGdprcomplianceConfig', - 'label' => __s('Setup'), - 'field' => 'plugin_gdprcompliance_config', - 'rights' => [READ =>__('Read'), UPDATE => __('Update')] - ), - array( - 'itemtype' => 'PluginGdprcomplianceHistory', - 'label' => __s('Historique'), - 'field' => 'plugin_gdprcompliance_history', - 'rights' => [READ=>__('Read')] - ), + array( + 'itemtype' => 'PluginGdprcomplianceConfig', + 'label' => __('Setup'), + 'field' => 'plugin_gdprcompliance_config', + 'rights' => [READ =>__('Read'), UPDATE => __('Update')] + ), + array( + 'itemtype' => 'PluginGdprcomplianceHistory', + 'label' => __('History', 'gdprcompliance'), + 'field' => 'plugin_gdprcompliance_history', + 'rights' => [READ=>__('Read')] + ), ); return $rights;
" . __("Date", 'gdprcompliance') . "" . __("Sucess", 'gdprcompliance') . "" . __("Success", 'gdprcompliance') . "" . __("Error", 'gdprcompliance') . "