Skip to content

Commit

Permalink
merge branch glpi10-portage to main
Browse files Browse the repository at this point in the history
  • Loading branch information
Philippe GODOT committed Apr 13, 2023
2 parents 19f339c + b993572 commit f45c254
Show file tree
Hide file tree
Showing 23 changed files with 1,546 additions and 883 deletions.
7 changes: 4 additions & 3 deletions ajax/get_renewal_tickets.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
$html .= '<form method="post" id="renewal_tickets_form" action="' . rtrim($CFG_GLPI['root_doc'], '/') . '/front/contract.form.php">' . "\n";
$html .= '<input type="hidden" name="entities_id" value="' . $task->fields['entities_id'] . '" />' . "\n";
$html .= '<input type="hidden" name="id" value="' . $contract_id . '" />' . "\n";
$html .= '<div id="moreDataContainer"></div>';
$html .= '<h2 style="text-align: center">';
$html .= 'Tickets';
$html .= '</h2>' . "\n";
Expand Down Expand Up @@ -88,10 +89,10 @@
$html .= __('Time');
$html .= '</th>' . "\n";
$html .= '<th>';
$html .= __('Open Date');
$html .= __('Opening date');
$html .= '</th>' . "\n";
$html .= '<th>';
$html .= __('Close Date');
$html .= __('Closing date');
$html .= '</th>' . "\n";
$html .= '</tr>' . "\n";

Expand Down Expand Up @@ -129,7 +130,7 @@

$html .= '<tr class="tab_bg_1">' . "\n";
$html .= '<td colspan="5" style="text-align: center">';
$html .= '<input type="submit" name="update" value="' . __('Link tickets to renewal', 'projectbridge') . '" class="submit" />';
$html .= '<input type="submit" name="update" id="renewal_tickets_form_submit" disabled value="' . __('Link tickets to renewal', 'projectbridge') . '" class="submit" />';
$html .= '</td>' . "\n";
$html .= '</tr>' . "\n";
$html .= '</table>' . "\n";
Expand Down
8 changes: 4 additions & 4 deletions ajax/get_tickets_actiontime.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@
$whereConditionsArray['is_private'] = 0;
}

$iterator = $DB->request([
$req = $DB->request([
'SELECT' => new QueryExpression('SUM(' . TicketTask::getTable() . '.actiontime) AS duration'),
'FROM' => TicketTask::getTable(),
'WHERE' => $whereConditionsArray
]);
if ($row = $iterator->next()) {
foreach ($req as $row) {
$totalActiontime = (int) $row['duration'];
}
if (!empty($totalActiontime)) {
Expand All @@ -40,12 +40,12 @@
$privateActiontime = 0;
if (Session::haveRight("task", CommonITILTask::SEEPRIVATE) && !$onlypublicTasks) {
$whereConditionsArray['is_private'] = 1;
$iterator = $DB->request([
$req = $DB->request([
'SELECT' => new QueryExpression('SUM(' . TicketTask::getTable() . '.actiontime) AS duration'),
'FROM' => TicketTask::getTable(),
'WHERE' => $whereConditionsArray
]);
if ($row = $iterator->next()) {
foreach ($req as $row) {
$privateActiontime = (int) $row['duration'];
}
if (!empty($privateActiontime)) {
Expand Down
55 changes: 43 additions & 12 deletions front/config.form.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,11 @@ function getPostDataFromFields(array $post_fields)

Html::header(__('ProjectBridge Configuration', 'projectbridge'), $_SERVER['PHP_SELF'], 'config', 'plugins');
echo '<div align="center">' . "\n";

echo '<div class="card">' . "\n";
echo '<h1>';
echo __('ProjectBridge Configuration', 'projectbridge');
echo '</h1>' . "\n";

echo '<hr />' . "\n";

if ($can_update) {
$post_fields = [
Expand All @@ -75,6 +74,7 @@ function getPostDataFromFields(array $post_fields)
'projectbridge_add_recipient_submit',
'projectbridge_config_countOnlyPublicTasks',
'projectbridge_config_addContractSelectorOnCreatingTicketForm',
'projectbridge_config_isRequiredContractSelectorOnCreatingTicketForm',
'projectbridge_config_elementsAssociateToExcessTicket',
'projectbridge_config_globalContractQuotaAlert'
];
Expand All @@ -91,10 +91,12 @@ function getPostDataFromFields(array $post_fields)
echo '</a>';

// status config

echo '<div class="card-header">' . "\n";
echo '<h2>';
echo __('Status Configuration', 'projectbridge');
echo '</h2>' . "\n";
echo '</div>' . "\n";
echo '<div class="card-body">' . "\n";

echo '<p>';
echo __('Please match the status names and their values in GLPI', 'projectbridge') . '.';
Expand Down Expand Up @@ -237,8 +239,6 @@ function getPostDataFromFields(array $post_fields)
echo '</table>' . "\n";
Html::closeForm();

echo '<hr />' . "\n";

// recipients config
$recipientIds = PluginProjectbridgeConfig::getConfValueByName('RecipientIds');
if (!$recipientIds) {
Expand All @@ -265,15 +265,18 @@ function getPostDataFromFields(array $post_fields)
$recipientIds[] = $recipient_user_id;
PluginProjectbridgeConfig::updateConfValue('RecipientIds', $recipientIds);
} else {
echo '<div class="warning">' . __('The selected user have no default email adress configured', 'projectbridge') . '</div>';
echo '<div class="warning">' . __('The selected user has no default email adress configured', 'projectbridge') . '</div>';
}
}
}
$recipients = PluginProjectbridgeConfig::getRecipients();

echo '</div>' . "\n";
echo '<div class="card-header">' . "\n";
echo '<h2>';
echo __('People receiving alerts', 'projectbridge');
echo '</h2>' . "\n";
echo '</div>' . "\n";
echo '<div class="card-body">' . "\n";

echo '<form method="post" action="">' . "\n";
echo '<table>' . "\n";
Expand Down Expand Up @@ -337,8 +340,12 @@ function getPostDataFromFields(array $post_fields)

echo '</table>' . "\n";
Html::closeForm();


echo '</div>' . "\n";
echo '<div class="card-header">' . "\n";
echo '<h2>' . __('General config', 'projectbridge') . '</h2>';
echo '</div>' . "\n";
echo '<div class="card-body">' . "\n";
echo '<form method="post" action="">' . "\n";
echo '<table>' . "\n";
echo '<thead>' . "\n";
Expand All @@ -357,7 +364,7 @@ function getPostDataFromFields(array $post_fields)
$countOnlyPublicTasks = $post_data['projectbridge_config_countOnlyPublicTasks'];
PluginProjectbridgeConfig::updateConfValue('CountOnlyPublicTasks', $countOnlyPublicTasks);
}
echo '<tr">' . "\n";
echo '<tr>' . "\n";
echo '<td>' . __('Count only public tasks in project', 'projectbridge') . '' . "\n";
echo '</td>' . "\n";
echo '<td>' . "\n";
Expand All @@ -371,21 +378,39 @@ function getPostDataFromFields(array $post_fields)
$addContractSelectorOnCreatingTicketForm = $post_data['projectbridge_config_addContractSelectorOnCreatingTicketForm'];
PluginProjectbridgeConfig::updateConfValue('AddContractSelectorOnCreatingTicketForm', $addContractSelectorOnCreatingTicketForm);
}
echo '<tr">' . "\n";
echo '<tr>' . "\n";
echo '<td>' . __('Add contract selector on creating ticket form', 'projectbridge') . '' . "\n";
echo '</td>' . "\n";
echo '<td>' . "\n";
Dropdown::showYesNo('projectbridge_config_addContractSelectorOnCreatingTicketForm', $addContractSelectorOnCreatingTicketForm, []);
echo '</span>';
echo '</td>' . "\n";
echo '</tr>' . "\n";

// isRequiredContractSelectorOnCreatingTicketForm
$isRequiredContractSelectorOnCreatingTicketForm = PluginProjectbridgeConfig::getConfValueByName('isRequiredContractSelectorOnCreatingTicketForm');
if (isset($post_data['projectbridge_config_isRequiredContractSelectorOnCreatingTicketForm'])) {
$isRequiredContractSelectorOnCreatingTicketForm = $post_data['projectbridge_config_isRequiredContractSelectorOnCreatingTicketForm'];
PluginProjectbridgeConfig::updateConfValue('isRequiredContractSelectorOnCreatingTicketForm', $isRequiredContractSelectorOnCreatingTicketForm);
}
$display = $isRequiredContractSelectorOnCreatingTicketForm?'block':'none';
echo '<tr id="isRequiredContractSelectorOnCreatingTicketForm" style=\"display:'.$display.';\">' . "\n";
echo '<td>' . __('Contract selector on creating ticket form is required', 'projectbridge') . '' . "\n";
echo '</td>' . "\n";
echo '<td>' . "\n";
Dropdown::showYesNo('projectbridge_config_isRequiredContractSelectorOnCreatingTicketForm', $isRequiredContractSelectorOnCreatingTicketForm, []);
echo '</span>';
echo '</td>' . "\n";
echo '</tr>' . "\n";


// projectbridge_config_globalContractQuotaAlert
$globalContractQuotaAlert = PluginProjectbridgeConfig::getConfValueByName('globalContractQuotaAlert');
if (isset($post_data['projectbridge_config_globalContractQuotaAlert'])) {
$globalContractQuotaAlert = $post_data['projectbridge_config_globalContractQuotaAlert'];
PluginProjectbridgeConfig::updateConfValue('globalContractQuotaAlert', $globalContractQuotaAlert);
}
echo '<tr">' . "\n";
echo '<tr>' . "\n";
echo '<td>' . __('Global percentage quota to send alert notification', 'projectbridge') . '' . "\n";
echo '</td>' . "\n";
echo '<td>' . "\n";
Expand Down Expand Up @@ -418,7 +443,7 @@ function getPostDataFromFields(array $post_fields)
$elementsAssociateToExcessTicket = $post_data['projectbridge_config_elementsAssociateToExcessTicket'];
PluginProjectbridgeConfig::updateConfValue('ElementsAssociateToExcessTicket', $elementsAssociateToExcessTicket);
}
echo '<tr">' . "\n";
echo '<tr>' . "\n";
echo '<td>' . __('Elements from previous ticket to be associated with renewed ticket', 'projectbridge') . '' . "\n";
echo '</td>' . "\n";
echo '<td>' . "\n";
Expand All @@ -431,6 +456,10 @@ function getPostDataFromFields(array $post_fields)
echo "<script type='text/javascript'>
//<![CDATA[
$(function() {
$('select[name=\"projectbridge_config_addContractSelectorOnCreatingTicketForm\"]').change(function() {
$('#isRequiredContractSelectorOnCreatingTicketForm').toggle();
});
$('#projectbridge_config_elementsAssociateToExcessTicket').select2({
width: '100%',
Expand Down Expand Up @@ -465,5 +494,7 @@ function getPostDataFromFields(array $post_fields)
echo '</b>';
}

echo '</div>' . "\n";
echo '</div>' . "\n";
echo '</div>' . "\n";
Html::footer();
44 changes: 19 additions & 25 deletions hook.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ function plugin_projectbridge_install()
$create_table_query = "
CREATE TABLE IF NOT EXISTS `" . PluginProjectbridgeEntity::$table_name . "`
(
`id` INT(11) NOT NULL AUTO_INCREMENT,
`id` INT(11) SIGNED NOT NULL AUTO_INCREMENT,
`entity_id` INT(11) NOT NULL,
`contract_id` INT(11) NOT NULL,
PRIMARY KEY (`id`),
INDEX (`entity_id`)
)
COLLATE='utf8_unicode_ci'
COLLATE='utf8mb4_unicode_ci'
ENGINE=InnoDB
";
$DB->query($create_table_query) or die($DB->error());
Expand All @@ -29,14 +29,14 @@ function plugin_projectbridge_install()
$create_table_query = "
CREATE TABLE IF NOT EXISTS `" . PluginProjectbridgeContract::$table_name . "`
(
`id` INT(11) NOT NULL AUTO_INCREMENT,
`id` INT(11) SIGNED NOT NULL AUTO_INCREMENT,
`contract_id` INT(11) NOT NULL,
`project_id` INT(11) NOT NULL,
`nb_hours` INT(11) NOT NULL,
PRIMARY KEY (`id`),
INDEX (`contract_id`)
)
COLLATE='utf8_unicode_ci'
COLLATE='utf8mb4_unicode_ci'
ENGINE=InnoDB
";
$DB->query($create_table_query) or die($DB->error());
Expand All @@ -46,14 +46,12 @@ function plugin_projectbridge_install()
$create_table_query = "
CREATE TABLE IF NOT EXISTS `" . PluginProjectbridgeTicket::$table_name . "`
(
`id` INT(11) NOT NULL AUTO_INCREMENT,
`id` INT(11) SIGNED NOT NULL AUTO_INCREMENT,
`ticket_id` INT(11) NOT NULL,
`projecttasks_id` INT(11) NOT NULL,
PRIMARY KEY (`id`),
INDEX (`ticket_id`)
)
COLLATE='utf8_unicode_ci'
ENGINE=InnoDB
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC
";
$DB->query($create_table_query) or die($DB->error());
} else {
Expand All @@ -69,13 +67,11 @@ function plugin_projectbridge_install()
$create_tableConfig_query = "
CREATE TABLE IF NOT EXISTS `" . PluginProjectbridgeConfig::$table_name . "`
(
`id` INT(11) NOT NULL AUTO_INCREMENT,
`id` INT(11) SIGNED NOT NULL AUTO_INCREMENT,
`name` VARCHAR(50) NOT NULL ,
`value` VARCHAR(250) NOT NULL,
PRIMARY KEY (`id`)
)
COLLATE='utf8_unicode_ci'
ENGINE=InnoDB
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC
";
if (!$DB->tableExists(PluginProjectbridgeConfig::$table_name)) {
$DB->query($create_tableConfig_query) or die($DB->error());
Expand Down Expand Up @@ -139,14 +135,12 @@ function plugin_projectbridge_install()
$create_table_query = "
CREATE TABLE IF NOT EXISTS `" . PluginProjectbridgeState::$table_name . "`
(
`id` INT(11) NOT NULL AUTO_INCREMENT,
`id` INT(11) SIGNED NOT NULL AUTO_INCREMENT,
`status` VARCHAR(250) NOT NULL,
`projectstates_id` INT(11) NOT NULL,
PRIMARY KEY (`id`),
INDEX (`status`)
)
COLLATE='utf8_unicode_ci'
ENGINE=InnoDB
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC
";
$DB->query($create_table_query) or die($DB->error());
}
Expand All @@ -155,13 +149,11 @@ function plugin_projectbridge_install()
$create_table_query = "
CREATE TABLE IF NOT EXISTS `" . PluginProjectbridgeContractQuotaAlert::$table_name . "`
(
`id` INT(11) NOT NULL AUTO_INCREMENT,
`id` INT(11) SIGNED NOT NULL AUTO_INCREMENT,
`contract_id` INT(11) NOT NULL,
`quotaAlert` INT(11) NOT NULL,
PRIMARY KEY (`id`)
)
COLLATE='utf8_unicode_ci'
ENGINE=InnoDB
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC
";
$DB->query($create_table_query) or die($DB->error());
}
Expand All @@ -172,7 +164,7 @@ function plugin_projectbridge_install()
$DB->query($delete_crontask_table) or die($DB->error());
}
if (version_compare(PLUGIN_PROJECTBRIDGE_VERSION, '2.3', '>')) {
$update_structure_query = "ALTER TABLE `" . PluginProjectbridgeConfig::$table_name . "` CHANGE `value` `value` VARCHAR(250) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL;";
$update_structure_query = "ALTER TABLE `" . PluginProjectbridgeConfig::$table_name . "` CHANGE `value` `value` VARCHAR(250) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL;";
$DB->query($update_structure_query) or die($DB->error());
}

Expand Down Expand Up @@ -294,6 +286,7 @@ function plugin_projectbridge_pre_contract_update(Contract $contract)
$update_val = $contract->input['update'] ?? $contract->input['_update'] ?? null;

if ($contract->canUpdate() && $update_val !== null && isset($contract->input['projectbridge_project_id'])) {

if ($update_val != __('Link tickets to renewal', 'projectbridge')) {
// update contract
$nb_hours = 0;
Expand Down Expand Up @@ -366,7 +359,8 @@ function plugin_projectbridge_pre_contract_update(Contract $contract)
*/
function plugin_projectbridge_contract_add(Contract $contract, $force = false)
{
if ($force === true || ($contract->canUpdate() && isset($contract->input['projectbridge_create_project']) && $contract->input['projectbridge_create_project'])) {

if ($force === true || ($contract->canUpdate() && isset($contract->input['projectbridge_create_project']) )) {
$nb_hours = 0;

if (!empty($contract->input['projectbridge_project_hours']) && $contract->input['projectbridge_project_hours'] > 0) {
Expand All @@ -381,7 +375,7 @@ function plugin_projectbridge_contract_add(Contract $contract, $force = false)
}

if (empty($begin_date)) {
Session::addMessageAfterRedirect(__('The contract has no start date. The project could not be created', 'projectbridge'), false, ERROR);
Session::addMessageAfterRedirect(__('The contract has no start date. The project could not be created.', 'projectbridge'), false, ERROR);
return false;
}

Expand Down Expand Up @@ -429,7 +423,7 @@ function plugin_projectbridge_contract_add(Contract $contract, $force = false)
$state_in_progress_value = PluginProjectbridgeState::getProjectStateIdByStatus('in_progress');

if (empty($state_in_progress_value)) {
Session::addMessageAfterRedirect(__('The correspondence for the status "In progress" has not been defined. The project could not be created', 'projectbridge'), false, ERROR);
Session::addMessageAfterRedirect(__('The correspondence for the status "In progress" has not been defined. The project could not be created.', 'projectbridge'), false, ERROR);
return false;
}

Expand Down Expand Up @@ -700,7 +694,7 @@ function plugin_projectbridge_getAddSearchOptionsNew($itemtype)
'id' => 4214,
'table' => PluginProjectbridgeTicket::$table_name,
'field' => 'project_id',
'name' => __('Is link to a project task', 'projectbridge').' ?',
'name' => __('Is linked to a project task', 'projectbridge').' ?',
'massiveaction' => false,
'datatype' => 'bool'
];
Expand Down
4 changes: 2 additions & 2 deletions inc/config.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ public static function getConfByName($name)
'FROM' => PluginProjectbridgeConfig::$table_name,
'WHERE' => ['name' => $name]
]);
if ($row = $req->next()) {
$conf = $row;
foreach ($req as $row) {
return $row;
}

return $conf;
Expand Down
Loading

0 comments on commit f45c254

Please sign in to comment.