PageRenderTime 50ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/glpi/inc/change_problem.class.php

#
PHP | 233 lines | 200 code | 2 blank | 31 comment | 1 complexity | 75862cc8390d95f9712941c426c21d60 MD5 | raw file
Possible License(s): GPL-2.0, GPL-3.0, LGPL-2.1
  1. <?php
  2. /*
  3. * @version $Id: change_problem.class.php 18771 2012-06-29 08:49:19Z moyo $
  4. -------------------------------------------------------------------------
  5. GLPI - Gestionnaire Libre de Parc Informatique
  6. Copyright (C) 2003-2012 by the INDEPNET Development Team.
  7. http://indepnet.net/ http://glpi-project.org
  8. -------------------------------------------------------------------------
  9. LICENSE
  10. This file is part of GLPI.
  11. GLPI is free software; you can redistribute it and/or modify
  12. it under the terms of the GNU General Public License as published by
  13. the Free Software Foundation; either version 2 of the License, or
  14. (at your option) any later version.
  15. GLPI is distributed in the hope that it will be useful,
  16. but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. GNU General Public License for more details.
  19. You should have received a copy of the GNU General Public License
  20. along with GLPI. If not, see <http://www.gnu.org/licenses/>.
  21. --------------------------------------------------------------------------
  22. */
  23. // ----------------------------------------------------------------------
  24. // Original Author of file: Julien Dombre
  25. // Purpose of file:
  26. // ----------------------------------------------------------------------
  27. if (!defined('GLPI_ROOT')) {
  28. die("Sorry. You can't access directly to this file");
  29. }
  30. class Change_Problem extends CommonDBRelation{
  31. // From CommonDBRelation
  32. public $itemtype_1 = 'Change';
  33. public $items_id_1 = 'changes_id';
  34. public $itemtype_2 = 'Problem';
  35. public $items_id_2 = 'problems_id';
  36. var $checks_only_for_itemtype1 = true;
  37. static function getTypeName($nb=0) {
  38. global $LANG;
  39. if ($nb>1) {
  40. return $LANG['setup'][624].' '.$LANG['change'][0].'-'.$LANG['problem'][0];
  41. }
  42. return $LANG['setup'][620].' '.$LANG['change'][0].'-'.$LANG['problem'][0];
  43. }
  44. /**
  45. * Get search function for the class
  46. *
  47. * @return array of search option
  48. **/
  49. function getSearchOptions() {
  50. return parent::getSearchOptions();
  51. }
  52. /**
  53. * Show tickets for a problem
  54. *
  55. * @param $problem Problem object
  56. **/
  57. static function showForProblem(Problem $problem) {
  58. global $DB, $CFG_GLPI, $LANG;
  59. $ID = $problem->getField('id');
  60. if (!$problem->can($ID,'r')) {
  61. return false;
  62. }
  63. $canedit = $problem->can($ID,'w');
  64. $rand = mt_rand();
  65. echo "<form name='changeproblem_form$rand' id='changeproblem_form$rand' method='post'
  66. action='";
  67. echo Toolbox::getItemTypeFormURL(__CLASS__)."'>";
  68. $colspan = 1;
  69. echo "<div class='center'><table class='tab_cadre_fixehov'>";
  70. echo "<tr><th colspan='2'>".$LANG['Menu'][8]."&nbsp;-&nbsp;";
  71. echo "<a href='".Toolbox::getItemTypeFormURL('Change')."?problems_id=$ID'>".$LANG['change'][2].
  72. "</a>";
  73. echo "</th>";
  74. if ($problem->isRecursive()) {
  75. echo "<th>".$LANG['entity'][0]."</th>";
  76. $colspan++;
  77. }
  78. echo "</tr>";
  79. $query = "SELECT DISTINCT `glpi_changes_problems`.`id` AS linkID,
  80. `glpi_changes`.*
  81. FROM `glpi_changes_problems`
  82. LEFT JOIN `glpi_changes`
  83. ON (`glpi_changes_problems`.`changes_id` = `glpi_changes`.`id`)
  84. WHERE `glpi_changes_problems`.`problems_id` = '$ID'
  85. ORDER BY `glpi_changes`.`name`";
  86. $result = $DB->query($query);
  87. $used = array();
  88. if ($DB->numrows($result) >0) {
  89. Session::initNavigateListItems('Change',
  90. $LANG['problem'][0] ." = ". $problem->fields["name"]);
  91. while ($data = $DB->fetch_array($result)) {
  92. $used[$data['id']] = $data['id'];
  93. Session::addToNavigateListItems('Change', $data["id"]);
  94. echo "<tr class='tab_bg_1'>";
  95. echo "<td width='10'>";
  96. if ($canedit) {
  97. echo "<input type='checkbox' name='item[".$data["linkID"]."]' value='1'>";
  98. } else {
  99. echo "&nbsp;";
  100. }
  101. echo "</td>";
  102. echo "<td><a href='".Toolbox::getItemTypeFormURL('Change')."?id=".$data['id']."'>".
  103. $data["name"]."</a></td>";
  104. if ($problem->isRecursive()) {
  105. echo "<td>".Dropdown::getDropdownName('glpi_entities', $data["entities_id"])."</td>";
  106. }
  107. echo "</tr>";
  108. }
  109. }
  110. if ($canedit) {
  111. echo "<tr class='tab_bg_2'><td class='right' colspan='$colspan'>";
  112. echo "<input type='hidden' name='problems_id' value='$ID'>";
  113. Dropdown::show('Change', array('used' => $used,
  114. 'entity' => $problem->getEntityID(),
  115. 'entity_sons' => $problem->isRecursive()));
  116. echo "</td><td class='center'>";
  117. echo "<input type='submit' name='add' value=\"".$LANG['buttons'][8]."\" class='submit'>";
  118. echo "</td></tr>";
  119. }
  120. echo "</table></div>";
  121. if ($canedit) {
  122. Html::openArrowMassives("changeproblem_form$rand", true);
  123. Html::closeArrowMassives(array('delete' => $LANG['buttons'][6]));
  124. }
  125. Html::closeForm();
  126. }
  127. /**
  128. * Show problems for a change
  129. *
  130. * @param $change Ticket object
  131. **/
  132. static function showForChange(Change $change) {
  133. global $DB, $CFG_GLPI, $LANG;
  134. $ID = $change->getField('id');
  135. if (!$change->can($ID,'r')) {
  136. return false;
  137. }
  138. $canedit = $change->can($ID,'w');
  139. $rand = mt_rand();
  140. echo "<form name='changeproblem_form$rand' id='changeproblem_form$rand' method='post'
  141. action='";
  142. echo Toolbox::getItemTypeFormURL(__CLASS__)."'>";
  143. $colspan = 1;
  144. echo "<div class='center'><table class='tab_cadre_fixehov'>";
  145. echo "<tr><th colspan='2'>".$LANG['Menu'][7]."</th></tr>";
  146. echo "<tr><th colspan='2'>".$LANG['common'][57]."</th>";
  147. echo "</tr>";
  148. $query = "SELECT DISTINCT `glpi_changes_problems`.`id` AS linkID,
  149. `glpi_problems`.*
  150. FROM `glpi_changes_problems`
  151. LEFT JOIN `glpi_problems`
  152. ON (`glpi_changes_problems`.`problems_id` = `glpi_problems`.`id`)
  153. WHERE `glpi_changes_problems`.`changes_id` = '$ID'
  154. ORDER BY `glpi_problems`.`name`";
  155. $result = $DB->query($query);
  156. $used = array();
  157. if ($DB->numrows($result) >0) {
  158. Session::initNavigateListItems('Problem',
  159. $LANG['change'][0] ." = ". $change->fields["name"]);
  160. while ($data = $DB->fetch_array($result)) {
  161. $used[$data['id']] = $data['id'];
  162. Session::addToNavigateListItems('Problem', $data["id"]);
  163. echo "<tr class='tab_bg_1'>";
  164. echo "<td width='10'>";
  165. if ($canedit) {
  166. echo "<input type='checkbox' name='item[".$data["linkID"]."]' value='1'>";
  167. } else {
  168. echo "&nbsp;";
  169. }
  170. echo "</td>";
  171. echo "<td><a href='".Toolbox::getItemTypeFormURL('Problem')."?id=".$data['id']."'>".
  172. $data["name"]."</a></td>";
  173. echo "</tr>";
  174. }
  175. }
  176. if ($canedit) {
  177. echo "<tr class='tab_bg_2'><td class='right' colspan='$colspan'>";
  178. echo "<input type='hidden' name='changes_id' value='$ID'>";
  179. Dropdown::show('Problem', array('used' => $used,
  180. 'entity' => $change->getEntityID()));
  181. echo "</td><td class='center'>";
  182. echo "<input type='submit' name='add' value=\"".$LANG['buttons'][8]."\" class='submit'>";
  183. echo "</td></tr>";
  184. }
  185. echo "</table></div>";
  186. if ($canedit) {
  187. Html::openArrowMassives("changeproblem_form$rand", true);
  188. Html::closeArrowMassives(array('delete' => $LANG['buttons'][6]));
  189. }
  190. Html::closeForm();
  191. }
  192. }
  193. ?>