Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/Contract_Item.php
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,14 @@
return false;
}

// If we are creating a project from a template, show read-only warning
if ($withtemplate == 2 && $item instanceof Project) {
echo '<div class="alert alert-info mb-3">';
echo '<i class="ti ti-info-circle me-2"></i>';
echo __('You are viewing contracts from the template. Save the project first to be able to add or modify contracts.');

Check failure on line 239 in src/Contract_Item.php

View workflow job for this annotation

GitHub Actions / Security scan

TaintedTextWithQuotes

src/Contract_Item.php:239:18: TaintedTextWithQuotes: Detected tainted text with possible quotes (see https://psalm.dev/274)

Check failure on line 239 in src/Contract_Item.php

View workflow job for this annotation

GitHub Actions / Security scan

TaintedHtml

src/Contract_Item.php:239:18: TaintedHtml: Detected tainted HTML (see https://psalm.dev/245)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
echo __('You are viewing contracts from the template. Save the project first to be able to add or modify contracts.');
echo __s('You are viewing contracts from the template. Save the project first to be able to add or modify contracts.');

echo '</div>';
}

switch ($item::class) {
case Contract::class:
self::showForContract($item, $withtemplate);
Expand Down
8 changes: 8 additions & 0 deletions src/Document_Item.php
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,14 @@
return false;
}

// If we are creating a project from a template, show read-only warning
if ($withtemplate == 2 && $item instanceof Project) {
echo '<div class="alert alert-info mb-3">';
echo '<i class="ti ti-info-circle me-2"></i>';
echo __('You are viewing documents from the template. Save the project first to be able to add or modify documents.');

Check failure on line 321 in src/Document_Item.php

View workflow job for this annotation

GitHub Actions / Security scan

TaintedTextWithQuotes

src/Document_Item.php:321:18: TaintedTextWithQuotes: Detected tainted text with possible quotes (see https://psalm.dev/274)

Check failure on line 321 in src/Document_Item.php

View workflow job for this annotation

GitHub Actions / Security scan

TaintedHtml

src/Document_Item.php:321:18: TaintedHtml: Detected tainted HTML (see https://psalm.dev/245)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
echo __('You are viewing documents from the template. Save the project first to be able to add or modify documents.');
echo __s('You are viewing documents from the template. Save the project first to be able to add or modify documents.');

echo '</div>';
}

if ($item instanceof Document && $tabnum === 1) {
return self::showForDocument($item);
}
Expand Down
16 changes: 13 additions & 3 deletions src/Item_Project.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,11 @@
* Print the HTML array for Items linked to a project
*
* @param Project $project
* @param int $withtemplate (default 0)
*
* @return bool
**/
public static function showForProject(Project $project): bool
public static function showForProject(Project $project, int $withtemplate = 0): bool
{
$instID = $project->getID();

Expand Down Expand Up @@ -169,7 +170,8 @@

TemplateRenderer::getInstance()->display('pages/tools/item_project.html.twig', [
'item' => $project,
'can_edit' => $canedit,
'can_edit' => $canedit && $withtemplate != 2,
'withtemplate' => $withtemplate,
'used' => $used,
'datatable_params' => [
'is_tab' => true,
Expand Down Expand Up @@ -245,8 +247,16 @@
return false;
}

// If we are creating a project from a template, show read-only warning
if ($withtemplate == 2 && $item instanceof Project) {
echo '<div class="alert alert-info mb-3">';
echo '<i class="ti ti-info-circle me-2"></i>';
echo __('You are viewing items from the template. Save the project first to be able to add or modify linked items.');

Check failure on line 254 in src/Item_Project.php

View workflow job for this annotation

GitHub Actions / Security scan

TaintedTextWithQuotes

src/Item_Project.php:254:18: TaintedTextWithQuotes: Detected tainted text with possible quotes (see https://psalm.dev/274)

Check failure on line 254 in src/Item_Project.php

View workflow job for this annotation

GitHub Actions / Security scan

TaintedHtml

src/Item_Project.php:254:18: TaintedHtml: Detected tainted HTML (see https://psalm.dev/245)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
echo __('You are viewing items from the template. Save the project first to be able to add or modify linked items.');
echo __s('You are viewing items from the template. Save the project first to be able to add or modify linked items.');

echo '</div>';
}

if ($item instanceof Project) {
return self::showForProject($item);
return self::showForProject($item, $withtemplate);
}

if (
Expand Down
17 changes: 13 additions & 4 deletions src/Itil_Project.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,26 +103,35 @@

public static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0)
{
// If we are creating a project from a template, show read-only warning
if ($withtemplate == 2 && $item instanceof Project) {
echo '<div class="alert alert-info mb-3">';
echo '<i class="ti ti-info-circle me-2"></i>';
echo __('You are viewing ITIL objects from the template. Save the project first to be able to add or modify linked tickets, problems or changes.');

Check failure on line 110 in src/Itil_Project.php

View workflow job for this annotation

GitHub Actions / Security scan

TaintedTextWithQuotes

src/Itil_Project.php:110:18: TaintedTextWithQuotes: Detected tainted text with possible quotes (see https://psalm.dev/274)

Check failure on line 110 in src/Itil_Project.php

View workflow job for this annotation

GitHub Actions / Security scan

TaintedHtml

src/Itil_Project.php:110:18: TaintedHtml: Detected tainted HTML (see https://psalm.dev/245)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
echo __('You are viewing ITIL objects from the template. Save the project first to be able to add or modify linked tickets, problems or changes.');
echo __s('You are viewing ITIL objects from the template. Save the project first to be able to add or modify linked tickets, problems or changes.');

echo '</div>';
}

switch ($item::class) {
case Change::class:
case Problem::class:
case Ticket::class:
return self::showForItil($item);

case Project::class:
return self::showForProject($item);
return self::showForProject($item, $withtemplate);
}
return false;
}

/**
* Show ITIL items for a project.
* ITIL items for a project.
*
* @param Project $project
* @param int $withtemplate (default 0)
*
* @return bool
**/
public static function showForProject(Project $project): bool
public static function showForProject(Project $project, int $withtemplate = 0): bool
{
global $DB, $CFG_GLPI;

Expand Down Expand Up @@ -177,7 +186,7 @@
];
}

if ($canedit) {
if ($canedit && $withtemplate != 2) {
$twig_params = [
'btn_msg' => _x('button', 'Add'),
'used' => $used,
Expand Down
11 changes: 10 additions & 1 deletion src/KnowbaseItem_Item.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,15 @@
if (!$item instanceof CommonDBTM) {
return false;
}

// If we are creating a project from a template, show read-only warning
if ($withtemplate == 2 && $item instanceof Project) {
echo '<div class="alert alert-info mb-3">';
echo '<i class="ti ti-info-circle me-2"></i>';
echo __('You are viewing knowledge base items from the template. Save the project first to be able to add or modify linked articles.');

Check failure on line 91 in src/KnowbaseItem_Item.php

View workflow job for this annotation

GitHub Actions / Security scan

TaintedTextWithQuotes

src/KnowbaseItem_Item.php:91:18: TaintedTextWithQuotes: Detected tainted text with possible quotes (see https://psalm.dev/274)

Check failure on line 91 in src/KnowbaseItem_Item.php

View workflow job for this annotation

GitHub Actions / Security scan

TaintedHtml

src/KnowbaseItem_Item.php:91:18: TaintedHtml: Detected tainted HTML (see https://psalm.dev/245)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
echo __('You are viewing knowledge base items from the template. Save the project first to be able to add or modify linked articles.');
echo __s('You are viewing knowledge base items from the template. Save the project first to be able to add or modify linked articles.');

echo '</div>';
}

self::showForItem($item, $withtemplate);
return true;
}
Expand Down Expand Up @@ -118,7 +127,7 @@
}

$rand = mt_rand();
if ($canedit && $ok_state) {
if ($canedit && $ok_state && $withtemplate != 2) {
if ($item::class !== KnowbaseItem::class) {
$visibility = KnowbaseItem::getVisibilityCriteria();
$condition = (isset($visibility['WHERE']) && count($visibility['WHERE'])) ? $visibility['WHERE'] : [];
Expand Down
8 changes: 8 additions & 0 deletions src/Notepad.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,14 @@ public static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $
return false;
}

// If we are creating a project from a template, show read-only warning
if ($withtemplate == 2 && $item instanceof Project) {
echo '<div class="alert alert-info mb-3">';
echo '<i class="ti ti-info-circle me-2"></i>';
echo __('You are viewing notes from the template. Save the project first to be able to add or modify notes.');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
echo __('You are viewing notes from the template. Save the project first to be able to add or modify notes.');
echo __s('You are viewing notes from the template. Save the project first to be able to add or modify notes.');

echo '</div>';
}

static::showForItem($item, $withtemplate);
return true;
}
Expand Down
5 changes: 3 additions & 2 deletions src/Project.php
Original file line number Diff line number Diff line change
Expand Up @@ -1420,14 +1420,15 @@ public static function getSpecificValueToSelect($field, $name = '', $values = ''
/**
* Show team for a project
* @param Project $project
* @param int $withtemplate (default 0)
* @return true
**/
public function showTeam(Project $project)
public function showTeam(Project $project, $withtemplate = 0)
{
$ID = $project->fields['id'];
$canedit = $project->can($ID, UPDATE);

if ($canedit) {
if ($canedit && $withtemplate != 2) {
$twig_params = [
'id' => $ID,
'label' => __('Add a team member'),
Expand Down
11 changes: 9 additions & 2 deletions src/ProjectCost.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,14 @@ public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0)
public static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0)
{
if ($item instanceof Project) {
return self::showForProject($item);
// If we are creating from a template, show read-only view with explanation
if ($withtemplate == 2) {
echo '<div class="alert alert-info mb-3">';
echo '<i class="ti ti-info-circle me-2"></i>';
echo __('You are viewing costs from the template. Save the project first to be able to add or modify costs.');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
echo __('You are viewing costs from the template. Save the project first to be able to add or modify costs.');
echo __s('You are viewing costs from the template. Save the project first to be able to add or modify costs.');

echo '</div>';
}
return self::showForProject($item, $withtemplate);
}
return false;
}
Expand Down Expand Up @@ -317,7 +324,7 @@ public static function showForProject(Project $project, $withtemplate = 0): bool

$rand = mt_rand();

if ($canedit) {
if ($canedit && $withtemplate != 2) {
echo "<div id='viewcost" . $ID . "_$rand'></div>\n";
echo "<script type='text/javascript' >\n";
echo "function viewAddCost" . $ID . "_$rand() {\n";
Expand Down
16 changes: 12 additions & 4 deletions src/ProjectTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -1211,7 +1211,7 @@ public function rawSearchOptions()
*
* @return void|false
**/
public static function showFor($item)
public static function showFor($item, $withtemplate = 0)
{
global $DB;

Expand Down Expand Up @@ -1288,7 +1288,7 @@ public static function showFor($item)
return;
}

if ($canedit) {
if ($canedit && $withtemplate != 2) {
// language=Twig
echo TemplateRenderer::getInstance()->renderFromStringTemplate(<<<TWIG
<div class="mb-3">
Expand All @@ -1297,7 +1297,7 @@ public static function showFor($item)
TWIG, ['projects_id' => $ID, 'btn_label' => _x('button', 'Add a task')]);
}

if ($item::class === self::class && $item->can($ID, UPDATE)) {
if ($item::class === self::class && $item->can($ID, UPDATE) && $withtemplate != 2) {
$twig_params = [
'projects_id' => $item->fields['projects_id'],
'projecttasks_id' => $ID,
Expand Down Expand Up @@ -1444,10 +1444,18 @@ public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0)

public static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0)
{
// If we are creating from a template, show read-only view with explanation
if ($withtemplate == 2) {
echo '<div class="alert alert-info mb-3">';
echo '<i class="ti ti-info-circle me-2"></i>';
echo __('You are viewing tasks from the template. Save the project first to be able to add or modify tasks.');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
echo __('You are viewing tasks from the template. Save the project first to be able to add or modify tasks.');
echo __s('You are viewing tasks from the template. Save the project first to be able to add or modify tasks.');

echo '</div>';
}

switch ($item::class) {
case Project::class:
case self::class:
self::showFor($item);
self::showFor($item, $withtemplate);
break;
}
return true;
Expand Down
9 changes: 8 additions & 1 deletion src/ProjectTeam.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,17 @@ public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0)

public static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0)
{
// If we are creating from a template, show read-only view with explanation
if ($withtemplate == 2) {
echo '<div class="alert alert-info mb-3">';
echo '<i class="ti ti-info-circle me-2"></i>';
echo __('You are viewing team members from the template. Save the project first to be able to add or modify team members.');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
echo __('You are viewing team members from the template. Save the project first to be able to add or modify team members.');
echo __s('You are viewing team members from the template. Save the project first to be able to add or modify team members.');

echo '</div>';
}

switch (get_class($item)) {
case Project::class:
$item->showTeam($item);
$item->showTeam($item, $withtemplate);
}
return true;
}
Expand Down
Loading