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

/glpi-pdf-0.83.3/pdf/inc/computer.class.php

#
PHP | 260 lines | 172 code | 59 blank | 29 comment | 14 complexity | 83ac6fe0f032a9802a8c141775f40b19 MD5 | raw file
Possible License(s): GPL-2.0
  1. <?php
  2. /*
  3. * @version $Id: computer.class.php 322 2012-04-06 17:03:33Z remi $
  4. -------------------------------------------------------------------------
  5. pdf - Export to PDF plugin for GLPI
  6. Copyright (C) 2003-2011 by the pdf Development Team.
  7. https://forge.indepnet.net/projects/pdf
  8. -------------------------------------------------------------------------
  9. LICENSE
  10. This file is part of pdf.
  11. pdf 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. pdf 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 pdf. If not, see <http://www.gnu.org/licenses/>.
  21. --------------------------------------------------------------------------
  22. */
  23. // Original Author of file: Remi Collet
  24. // ----------------------------------------------------------------------
  25. class PluginPdfComputer extends PluginPdfCommon {
  26. function __construct(CommonGLPI $obj=NULL) {
  27. $this->obj = ($obj ? $obj : new Computer());
  28. }
  29. function defineAllTabs($options=array()) {
  30. $onglets = parent::defineAllTabs($options);
  31. unset($onglets['OcsLink$1']); // TODO add method to print OCS
  32. unset($onglets['Item_Problem$1']); // TODO add method to print linked Problems
  33. return $onglets;
  34. }
  35. static function pdfMain(PluginPdfSimplePDF $pdf, Computer $computer){
  36. global $DB, $LANG;
  37. $ID = $computer->getField('id');
  38. $pdf->setColumnsSize(50,50);
  39. $col1 = '<b>'.$LANG['common'][2].' '.$computer->fields['id'].'</b>';
  40. $col2 = $LANG['common'][26].' : '.Html::convDateTime($computer->fields['date_mod']);
  41. if(!empty($computer->fields['template_name'])) {
  42. $col2 .= ' ('.$LANG['common'][13].' : '.$computer->fields['template_name'].')';
  43. } else if($computer->fields['is_ocs_import']) {
  44. $col2 .= ' ('.$LANG['ocsng'][7].')';
  45. }
  46. $pdf->displayTitle($col1, $col2);
  47. $pdf->displayLine(
  48. '<b><i>'.$LANG['common'][16].' :</i></b> '.$computer->fields['name'],
  49. '<b><i>'.$LANG['state'][0].' :</i></b> '.
  50. Html::clean(Dropdown::getDropdownName('glpi_states',$computer->fields['states_id'])));
  51. $pdf->displayLine(
  52. '<b><i>'.$LANG['common'][15].' :</i></b> '.
  53. Html::clean(Dropdown::getDropdownName('glpi_locations', $computer->fields['locations_id'])),
  54. '<b><i>'.$LANG['common'][17].' :</i></b> '.
  55. Html::clean(Dropdown::getDropdownName('glpi_computertypes',
  56. $computer->fields['computertypes_id'])));
  57. $pdf->displayLine(
  58. '<b><i>'.$LANG['common'][10].' :</i></b> '.getUserName($computer->fields['users_id_tech']),
  59. '<b><i>'.$LANG['common'][5].' :</i></b> '.
  60. Html::clean(Dropdown::getDropdownName('glpi_manufacturers',
  61. $computer->fields['manufacturers_id'])));
  62. $pdf->displayLine(
  63. '<b><i>'.$LANG['common'][109].' :</i></b> '.
  64. Html::clean(Dropdown::getDropdownName('glpi_groups',$computer->fields['groups_id_tech'])),
  65. '<b><i>'.$LANG['common'][22].' :</i></b> '.
  66. Html::clean(Dropdown::getDropdownName('glpi_computermodels',
  67. $computer->fields['computermodels_id'])));
  68. $pdf->displayLine(
  69. '<b><i>'.$LANG['common'][21].' :</i></b> '.$computer->fields['contact_num'],
  70. '<b><i>'.$LANG['common'][19].' :</i></b> '.$computer->fields['serial']);
  71. $pdf->displayLine('<b><i>'.$LANG['common'][18].' :</i></b> '.$computer->fields['contact'],
  72. '<b><i>'.$LANG['common'][20].' :</i></b> '.$computer->fields['otherserial']);
  73. $pdf->displayLine(
  74. '<b><i>'.$LANG['common'][34].' :</i></b> '.getUserName($computer->fields['users_id']),
  75. '<b><i>'.$LANG['setup'][88].' :</i></b> '.
  76. Html::clean(Dropdown::getDropdownName('glpi_networks', $computer->fields['networks_id'])));
  77. $pdf->displayLine(
  78. '<b><i>'.$LANG['common'][35].' :</i></b> '.
  79. Html::clean(Dropdown::getDropdownName('glpi_groups',$computer->fields['groups_id'])),
  80. '<b><i>'.$LANG['computers'][53].' :</i></b> '.
  81. Html::clean(Dropdown::getDropdownName('glpi_operatingsystemservicepacks',
  82. $computer->fields['operatingsystemservicepacks_id'])));
  83. $pdf->displayLine(
  84. '<b><i>'.$LANG['setup'][89].' :</i></b> '.
  85. Html::clean(Dropdown::getDropdownName('glpi_domains', $computer->fields['domains_id'])),
  86. '<b><i>'.$LANG['computers'][52].' :</i></b> '.
  87. Html::clean(Dropdown::getDropdownName('glpi_operatingsystemversions',
  88. $computer->fields['operatingsystemversions_id'])));
  89. $pdf->displayLine(
  90. '<b><i>'.$LANG['computers'][9].' :</i></b> '.
  91. Html::clean(Dropdown::getDropdownName('glpi_operatingsystems',
  92. $computer->fields['operatingsystems_id'])),
  93. '<b><i>'.$LANG['computers'][10].' :</i></b> '.$computer->fields['os_license_number']);
  94. $pdf->displayLine(
  95. '<b><i>'.$LANG['computers'][11].' :</i></b> '.$computer->fields['os_licenseid'],
  96. '<b><i>'.$LANG['computers'][51].' :</i></b> '.
  97. Html::clean(Dropdown::getDropdownName('glpi_autoupdatesystems',
  98. $computer->fields['autoupdatesystems_id'])));
  99. $pdf->setColumnsSize(100);
  100. if ($computer->fields['is_ocs_import'] && Session::haveRight("view_ocsng","r")) {
  101. $tmp = '';
  102. $query = "SELECT *
  103. FROM `glpi_ocslinks`
  104. WHERE `computers_id` = '$ID'";
  105. $result = $DB->query($query);
  106. if ($DB->numrows($result)==1) {
  107. $dataocs = $DB->fetch_array($result);
  108. $tmp .= '<b>'.$LANG['ocsng'][14].'</b> : '.Html::convDateTime($dataocs["last_ocs_update"]).', ';
  109. $tmp .= '<b>'.$LANG['ocsng'][13].'</b> : '.Html::convDateTime($dataocs["last_update"]).', ';
  110. }
  111. $tmp .= '<b>'.$LANG['ocsng'][6].'</b> : '.
  112. ($computer->getField('use_auto_update') ? $LANG['choice'][1] : $LANG['choice'][0]);
  113. $pdf->displayText('<b>'.$LANG['ocsng'][0].'</b> : ', $tmp);
  114. }
  115. $pdf->displayLine(
  116. '<b><i>'.$LANG['computers'][58].' :</i></b> '.$computer->fields['uuid']);
  117. $pdf->displayText('<b><i>'.$LANG['common'][25].' :</i></b>', $computer->fields['comment']);
  118. $pdf->displaySpace();
  119. }
  120. static function pdfDevice(PluginPdfSimplePDF $pdf, Computer $computer) {
  121. global $DB, $LANG;
  122. $devtypes = Computer_Device::getDeviceTypes();
  123. $ID = $computer->getField('id');
  124. if (!$computer->can($ID, 'r')) {
  125. return false;
  126. }
  127. $pdf->setColumnsSize(100);
  128. $pdf->displayTitle('<b>'.Toolbox::ucfirst($LANG['log'][18]).'</b>');
  129. $pdf->setColumnsSize(3,14,42,41);
  130. foreach ($devtypes as $itemtype) {
  131. $device = new $itemtype;
  132. $specificities = $device->getSpecifityLabel();
  133. $specif_fields = array_keys($specificities);
  134. $specif_text = implode(',',$specif_fields);
  135. if (!empty($specif_text)) {
  136. $specif_text=" ,".$specif_text." ";
  137. }
  138. $linktable = getTableForItemType('Computer_'.$itemtype);
  139. $fk = getForeignKeyFieldForTable(getTableForItemType($itemtype));
  140. $query = "SELECT count(*) AS NB, `id`, `$fk` $specif_text
  141. FROM `$linktable`
  142. WHERE `computers_id` = '$ID'
  143. GROUP BY `$fk` $specif_text";
  144. foreach($DB->request($query) as $data) {
  145. if ($device->getFromDB($data[$fk])) {
  146. $spec = $device->getFormData();
  147. $col4 = '';
  148. if (isset($spec['label']) && count($spec['label'])) {
  149. $colspan = (60/count($spec['label']));
  150. foreach ($spec['label'] as $i => $label) {
  151. if (isset($spec['value'][$i])) {
  152. $col4 .= '<b><i>'.$spec['label'][$i].' :</i></b> '.$spec['value'][$i]." ";
  153. } else {
  154. $col4 .= '<b><i>'.$spec['label'][$i].' :</i></b> '.$data['specificity']." ";
  155. }
  156. }
  157. }
  158. $pdf->displayLine($data['NB'], $device->getTypeName(), $device->getName(), $col4);
  159. }
  160. }
  161. }
  162. $pdf->displaySpace();
  163. }
  164. static function displayTabContentForPDF(PluginPdfSimplePDF $pdf, CommonGLPI $item, $tab) {
  165. switch ($tab) {
  166. case '_main_' :
  167. self::pdfMain($pdf, $item);
  168. break;
  169. case 'DeviceProcessor$1' :
  170. self::pdfDevice($pdf, $item);
  171. break;
  172. case 'ComputerDisk$1' :
  173. PluginPdfComputerDisk::pdfForComputer($pdf, $item);
  174. break;
  175. case 'Computer_SoftwareVersion$1' :
  176. PluginPdfComputer_SoftwareVersion::pdfForComputer($pdf, $item);
  177. break;
  178. case 'Computer_Item$1' :
  179. PluginPdfComputer_Item::pdfForComputer($pdf, $item);
  180. break;
  181. case 'Document$1' :
  182. PluginPdfDocument::pdfForItem($pdf, $item);
  183. break;
  184. case 'ComputerVirtualMachine$1' :
  185. PluginPdfComputerVirtualMachine::pdfForComputer($pdf, $item);
  186. break;
  187. case 'RegistryKey$1' :
  188. PluginPdfRegistryKey::pdfForComputer($pdf, $item);
  189. break;
  190. default :
  191. return false;
  192. }
  193. return true;
  194. }
  195. }