diff --git a/src/Contract_Item.php b/src/Contract_Item.php
index 15f3525a1ce..902ffdfe9d6 100644
--- a/src/Contract_Item.php
+++ b/src/Contract_Item.php
@@ -232,6 +232,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 '
';
+ echo '';
+ echo __s('You are viewing contracts from the template. Save the project first to be able to add or modify contracts.');
+ echo '
';
+ }
+
switch ($item::class) {
case Contract::class:
self::showForContract($item, $withtemplate);
diff --git a/src/Document_Item.php b/src/Document_Item.php
index 980b4f2d8f3..4b5cb49117c 100644
--- a/src/Document_Item.php
+++ b/src/Document_Item.php
@@ -314,6 +314,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 '';
+ echo '';
+ echo __s('You are viewing documents from the template. Save the project first to be able to add or modify documents.');
+ echo '
';
+ }
+
if ($item instanceof Document && $tabnum === 1) {
return self::showForDocument($item);
}
diff --git a/src/Item_Project.php b/src/Item_Project.php
index 878912c8dd3..111d354282b 100644
--- a/src/Item_Project.php
+++ b/src/Item_Project.php
@@ -86,10 +86,11 @@ public function prepareInputForAdd($input)
* 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();
@@ -169,7 +170,8 @@ public static function showForProject(Project $project): bool
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,
@@ -245,8 +247,16 @@ 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 '';
+ echo '';
+ echo __s('You are viewing items from the template. Save the project first to be able to add or modify linked items.');
+ echo '
';
+ }
+
if ($item instanceof Project) {
- return self::showForProject($item);
+ return self::showForProject($item, $withtemplate);
}
if (
diff --git a/src/Itil_Project.php b/src/Itil_Project.php
index b42b81b3a16..a3577383d58 100644
--- a/src/Itil_Project.php
+++ b/src/Itil_Project.php
@@ -103,6 +103,14 @@ public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0)
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 '';
+ echo '';
+ 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 '
';
+ }
+
switch ($item::class) {
case Change::class:
case Problem::class:
@@ -110,19 +118,20 @@ public static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $
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;
@@ -177,7 +186,7 @@ public static function showForProject(Project $project): bool
];
}
- if ($canedit) {
+ if ($canedit && $withtemplate != 2) {
$twig_params = [
'btn_msg' => _x('button', 'Add'),
'used' => $used,
diff --git a/src/KnowbaseItem_Item.php b/src/KnowbaseItem_Item.php
index 9133bfe954f..b432f09d648 100644
--- a/src/KnowbaseItem_Item.php
+++ b/src/KnowbaseItem_Item.php
@@ -83,6 +83,15 @@ public static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $
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 '';
+ echo '';
+ 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 '
';
+ }
+
self::showForItem($item, $withtemplate);
return true;
}
@@ -118,7 +127,7 @@ public static function showForItem(CommonDBTM $item, $withtemplate = 0)
}
$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'] : [];
diff --git a/src/Notepad.php b/src/Notepad.php
index 97636fec8b1..eba72784858 100644
--- a/src/Notepad.php
+++ b/src/Notepad.php
@@ -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 '';
+ echo '';
+ echo __s('You are viewing notes from the template. Save the project first to be able to add or modify notes.');
+ echo '
';
+ }
+
static::showForItem($item, $withtemplate);
return true;
}
diff --git a/src/Project.php b/src/Project.php
index b11c217f1f5..6354039c35d 100644
--- a/src/Project.php
+++ b/src/Project.php
@@ -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'),
diff --git a/src/ProjectCost.php b/src/ProjectCost.php
index 2e1052f3a8b..5daa14d4ffa 100644
--- a/src/ProjectCost.php
+++ b/src/ProjectCost.php
@@ -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 '';
+ echo '';
+ echo __s('You are viewing costs from the template. Save the project first to be able to add or modify costs.');
+ echo '
';
+ }
+ return self::showForProject($item, $withtemplate);
}
return false;
}
@@ -317,7 +324,7 @@ public static function showForProject(Project $project, $withtemplate = 0): bool
$rand = mt_rand();
- if ($canedit) {
+ if ($canedit && $withtemplate != 2) {
echo "\n";
echo "