schema.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475
  1. <?php
  2. require_once('../application/application.inc.php');
  3. require_once('../application/itopwebpage.class.inc.php');
  4. require_once('../application/startup.inc.php');
  5. /**
  6. * Helper for this page -> link to a class
  7. */
  8. function MakeClassHLink($sClass)
  9. {
  10. return "<a href=\"?operation=details_class&class=$sClass\" title=\"".MetaModel::GetClassDescription($sClass)."\">".MetaModel::GetName($sClass)."</a>";
  11. }
  12. /**
  13. * Helper for this page -> link to a class
  14. */
  15. function MakeRelationHLink($sRelCode)
  16. {
  17. $sDec = MetaModel::GetRelationProperty($sRelCode, 'description');
  18. //$sVerbDown = MetaModel::GetRelationProperty($sRelCode, 'verb_down');
  19. //$sVerbUp = MetaModel::GetRelationProperty($sRelCode, 'verb_up');
  20. return "<a href=\"?operation=details_relation&relcode=$sRelCode\" title=\"$sDec\">".$sRelCode."</a>";
  21. }
  22. /**
  23. * Helper for the global list and the details of a given class
  24. */
  25. function DisplaySubclasses($oPage, $sClass)
  26. {
  27. $aChildClasses = MetaModel::EnumChildClasses($sClass);
  28. if (count($aChildClasses) != 0)
  29. {
  30. $oPage->add("<ul>\n");
  31. foreach($aChildClasses as $sClassName)
  32. {
  33. // Skip indirect childs, they will be handled somewhere else
  34. if (MetaModel::GetParentPersistentClass($sClassName) == $sClass)
  35. {
  36. $oPage->add("<li>".MakeClassHLink($sClassName)."\n");
  37. DisplaySubclasses($oPage, $sClassName);
  38. $oPage->add("</li>\n");
  39. }
  40. }
  41. $oPage->add("</ul>\n");
  42. }
  43. }
  44. /**
  45. * Helper for the global list and the details of a given class
  46. */
  47. function DisplayReferencingClasses($oPage, $sClass)
  48. {
  49. $bSkipLinkingClasses = false;
  50. $aRefs = MetaModel::EnumReferencingClasses($sClass, $bSkipLinkingClasses);
  51. if (count($aRefs) != 0)
  52. {
  53. $oPage->add("<ul>\n");
  54. foreach ($aRefs as $sRemoteClass => $aRemoteKeys)
  55. {
  56. foreach ($aRemoteKeys as $sExtKeyAttCode)
  57. {
  58. $oPage->add("<li>".MakeClassHLink($sRemoteClass)." by <em>$sExtKeyAttCode</em></li>\n");
  59. }
  60. }
  61. $oPage->add("</ul>\n");
  62. }
  63. }
  64. /**
  65. * Helper for the global list and the details of a given class
  66. */
  67. function DisplayLinkingClasses($oPage, $sClass)
  68. {
  69. $bSkipLinkingClasses = false;
  70. $aRefs = MetaModel::EnumLinkingClasses($sClass);
  71. if (count($aRefs) != 0)
  72. {
  73. $oPage->add("<ul>\n");
  74. foreach ($aRefs as $sLinkClass => $aRemoteClasses)
  75. {
  76. foreach($aRemoteClasses as $sExtKeyAttCode => $sRemoteClass)
  77. {
  78. $oPage->add("<li>".MakeClassHLink($sRemoteClass)." by <em>".MakeClassHLink($sLinkClass)."::$sExtKeyAttCode</em></li>\n");
  79. }
  80. }
  81. $oPage->add("</ul>\n");
  82. }
  83. }
  84. /**
  85. * Helper for the global list and the details of a given class
  86. */
  87. function DisplayRelatedClassesBestInClass($oPage, $sClass, $iLevels = 20, &$aVisitedClasses = array(), $bSubtree = true)
  88. {
  89. if ($iLevels <= 0) return;
  90. $iLevels--;
  91. if (array_key_exists($sClass, $aVisitedClasses)) return;
  92. $aVisitedClasses[$sClass] = true;
  93. if ($bSubtree) $oPage->add("<ul class=\"treeview\">\n");
  94. foreach (MetaModel::EnumParentClasses($sClass) as $sParentClass)
  95. {
  96. DisplayRelatedClassesBestInClass($oPage, $sParentClass, $iLevels, $aVisitedClasses, false);
  97. }
  98. ////$oPage->add("<div style=\"background-color:#ccc; border: 1px dashed #333;\">");
  99. foreach (MetaModel::EnumReferencedClasses($sClass) as $sExtKeyAttCode => $sRemoteClass)
  100. {
  101. $sVisited = (array_key_exists($sRemoteClass, $aVisitedClasses)) ? " ..." : "";
  102. if (MetaModel::GetAttributeOrigin($sClass, $sExtKeyAttCode) == $sClass)
  103. {
  104. $oPage->add("<li>$sClass| <em>$sExtKeyAttCode</em> =&gt;".MakeClassHLink($sRemoteClass)."$sVisited</li>\n");
  105. DisplayRelatedClassesBestInClass($oPage, $sRemoteClass, $iLevels, $aVisitedClasses);
  106. }
  107. }
  108. foreach (MetaModel::EnumReferencingClasses($sClass) as $sRemoteClass => $aRemoteKeys)
  109. {
  110. foreach ($aRemoteKeys as $sExtKeyAttCode)
  111. {
  112. $sVisited = (array_key_exists($sRemoteClass, $aVisitedClasses)) ? " ..." : "";
  113. $oPage->add("<li>$sClass| &lt;=".MakeClassHLink($sRemoteClass)."::<em>$sExtKeyAttCode</em>$sVisited</li>\n");
  114. DisplayRelatedClassesBestInClass($oPage, $sRemoteClass, $iLevels, $aVisitedClasses);
  115. }
  116. }
  117. ////$oPage->add("</div>");
  118. if ($bSubtree) $oPage->add("</ul>\n");
  119. }
  120. /**
  121. * Helper for the list of classes related to the given class
  122. */
  123. function DisplayRelatedClasses($oPage, $sClass)
  124. {
  125. $oPage->add("<h3>Childs</h3>\n");
  126. DisplaySubclasses($oPage, $sClass);
  127. $oPage->add("<h3>Pointed to by...</h3>\n");
  128. DisplayReferencingClasses($oPage, $sClass);
  129. $oPage->add("<h3>Linked to ...</h3>\n");
  130. DisplayLinkingClasses($oPage, $sClass);
  131. $oPage->add("<h3>ZE Graph ...</h3>\n");
  132. DisplayRelatedClassesBestInClass($oPage, $sClass, 4);
  133. }
  134. /**
  135. * Helper for the lifecycle details of a given class
  136. */
  137. function DisplayLifecycle($oPage, $sClass)
  138. {
  139. $sStateAttCode = MetaModel::GetStateAttributeCode($sClass);
  140. if (empty($sStateAttCode))
  141. {
  142. $oPage->p("no lifecycle for this class");
  143. }
  144. else
  145. {
  146. $aStates = MetaModel::EnumStates($sClass);
  147. $aStimuli = MetaModel::EnumStimuli($sClass);
  148. $oPage->add("<img src=\"../pages/graphviz.php?class=$sClass\">\n");
  149. $oPage->add("<h3>Transitions</h3>\n");
  150. $oPage->add("<ul>\n");
  151. foreach ($aStates as $sStateCode => $aStateDef)
  152. {
  153. $sStateLabel = $aStates[$sStateCode]['label'];
  154. $sStateDescription = $aStates[$sStateCode]['description'];
  155. $oPage->add("<li title=\"code: $sStateCode\">$sStateLabel <span style=\"color:grey;\">($sStateDescription)</span></li>\n");
  156. $oPage->add("<ul>\n");
  157. foreach(MetaModel::EnumTransitions($sClass, $sStateCode) as $sStimulusCode => $aTransitionDef)
  158. {
  159. $sStimulusLabel = $aStimuli[$sStimulusCode]->Get('label');
  160. $sTargetStateLabel = $aStates[$aTransitionDef['target_state']]['label'];
  161. if (count($aTransitionDef['actions']) > 0)
  162. {
  163. $sActions = " <em>(".implode(', ', $aTransitionDef['actions']).")</em>";
  164. }
  165. else
  166. {
  167. $sActions = "";
  168. }
  169. $oPage->add("<li><span style=\"color:red;font-weight=bold;\">$sStimulusLabel</span> =&gt; $sTargetStateLabel $sActions</li>\n");
  170. }
  171. $oPage->add("</ul>\n");
  172. }
  173. $oPage->add("</ul>\n");
  174. $oPage->add("<h3>Attribute options</h3>\n");
  175. $oPage->add("<ul>\n");
  176. foreach ($aStates as $sStateCode => $aStateDef)
  177. {
  178. $sStateLabel = $aStates[$sStateCode]['label'];
  179. $sStateDescription = $aStates[$sStateCode]['description'];
  180. $oPage->add("<li title=\"code: $sStateCode\">$sStateLabel <span style=\"color:grey;\">($sStateDescription)</span></li>\n");
  181. if (count($aStates[$sStateCode]['attribute_list']) > 0)
  182. {
  183. $oPage->add("<ul>\n");
  184. foreach($aStates[$sStateCode]['attribute_list'] as $sAttCode => $iOptions)
  185. {
  186. $oAttDef = MetaModel::GetAttributeDef($sClass, $sAttCode);
  187. $sAttLabel = $oAttDef->GetLabel();
  188. $aOptions = array();
  189. if ($iOptions & OPT_ATT_HIDDEN) $aOptions[] = 'Hidden';
  190. if ($iOptions & OPT_ATT_READONLY) $aOptions[] = 'Read-only';
  191. if ($iOptions & OPT_ATT_MANDATORY) $aOptions[] = 'Mandatory';
  192. if ($iOptions & OPT_ATT_MUSTCHANGE) $aOptions[] = 'Must change';
  193. if ($iOptions & OPT_ATT_MUSTPROMPT) $aOptions[] = 'Must be proposed for changing';
  194. if (count($aOptions))
  195. {
  196. $sOptions = implode(', ', $aOptions);
  197. }
  198. else
  199. {
  200. $sOptions = "";
  201. }
  202. $oPage->add("<li><span style=\"color:purple;font-weight=bold;\">$sAttLabel</span> $sOptions</li>\n");
  203. }
  204. $oPage->add("</ul>\n");
  205. }
  206. else
  207. {
  208. $oPage->p("<em>empty list</em>");
  209. }
  210. }
  211. $oPage->add("</ul>\n");
  212. }
  213. }
  214. /**
  215. * Display the list of classes from the business model
  216. */
  217. function DisplayClassesList($oPage)
  218. {
  219. $oPage->add("<h1>iTop objects schema</h1>\n");
  220. $oPage->add("<ul id=\"ClassesList\" class=\"treeview fileview\">\n");
  221. foreach(MetaModel::EnumCategories() as $sCategory)
  222. {
  223. if (empty($sCategory)) continue; // means 'all' -> skip
  224. $sClosed = ($sCategory == 'bizmodel') ? '' : ' class="closed"';
  225. $oPage->add("<li$sClosed>Category <b>$sCategory</b>\n");
  226. $oPage->add("<ul>\n");
  227. foreach(MetaModel::GetClasses($sCategory) as $sClassName)
  228. {
  229. if (MetaModel::IsStandaloneClass($sClassName))
  230. {
  231. $oPage->add("<li>".MakeClassHLink($sClassName)."</li>\n");
  232. }
  233. else if (MetaModel::IsRootClass($sClassName))
  234. {
  235. $oPage->add("<li class=\"closed\">".MakeClassHLink($sClassName)."\n");
  236. DisplaySubclasses($oPage, $sClassName);
  237. $oPage->add("</li>\n");
  238. }
  239. }
  240. $oPage->add("</ul>\n");
  241. $oPage->add("</li>\n");
  242. }
  243. $oPage->add("</ul>\n");
  244. $oPage->add("<h1>Relationships</h1>\n");
  245. $oPage->add("<ul id=\"ClassesRelationships\" class=\"treeview\">\n");
  246. foreach (MetaModel::EnumRelations() as $sRelCode)
  247. {
  248. $oPage->add("<li>".MakeRelationHLink($sRelCode)."\n");
  249. $oPage->add("<ul>\n");
  250. foreach (MetaModel::EnumRelationProperties($sRelCode) as $sProp => $sValue)
  251. {
  252. $oPage->add("<li>$sProp: ".htmlentities($sValue)."</li>\n");
  253. }
  254. $oPage->add("</ul>\n");
  255. $oPage->add("</li>\n");
  256. }
  257. $oPage->add("</ul>\n");
  258. $oPage->add_ready_script('$("#ClassesList").treeview();');
  259. $oPage->add_ready_script('$("#ClassesRelationships").treeview();');
  260. }
  261. /**
  262. * Display the details of a given class of objects
  263. */
  264. function DisplayClassDetails($oPage, $sClass)
  265. {
  266. $oPage->p("<h2>$sClass</h2><br/>\n".MetaModel::GetClassDescription($sClass)."<br/>\n");
  267. $oPage->p("<h3>Class Hierarchy</h3>");
  268. $oPage->p("[<a href=\"?operation='list'\">All classes</a>]");
  269. // List the parent classes
  270. $sParent = MetaModel::GetParentPersistentClass($sClass);
  271. $aParents = array();
  272. $aParents[] = $sClass;
  273. while($sParent != "" && $sParent != 'cmdbAbstractObject')
  274. {
  275. $aParents[] = $sParent;
  276. $sParent = MetaModel::GetParentPersistentClass($sParent);
  277. }
  278. $iIndex = count($aParents);
  279. $sSpace ="";
  280. $oPage->add("<ul id=\"ClassHierarchy\">");
  281. while ($iIndex > 0)
  282. {
  283. $iIndex--;
  284. $oPage->add("<li>".MakeClassHLink($aParents[$iIndex])."\n");
  285. $oPage->add("<ul>\n");
  286. }
  287. for($iIndex = 0; $iIndex < count($aParents); $iIndex++)
  288. {
  289. $oPage->add("</ul>\n</li>\n");
  290. }
  291. $oPage->add("</ul>\n");
  292. $oPage->add_ready_script('$("#ClassHierarchy").treeview();');
  293. $oPage->p('');
  294. $oPage->AddTabContainer('details');
  295. $oPage->SetCurrentTabContainer('details');
  296. // List the attributes of the object
  297. $aDetails = array();
  298. foreach(MetaModel::ListAttributeDefs($sClass) as $sAttCode=>$oAttDef)
  299. {
  300. if ($oAttDef->IsExternalKey())
  301. {
  302. $sValue = "External key to ".MakeClassHLink($oAttDef->GetTargetClass());
  303. }
  304. else
  305. {
  306. $sValue = $oAttDef->GetDescription();
  307. }
  308. $sType = $oAttDef->GetType().' ('.$oAttDef->GetTypeDesc().')';
  309. $sOrigin = MetaModel::GetAttributeOrigin($sClass, $sAttCode);
  310. $sAllowedValues = "";
  311. $oAllowedValuesDef = $oAttDef->GetValuesDef();
  312. $sMoreInfo = "";
  313. if (is_subclass_of($oAttDef, 'AttributeDBFieldVoid'))
  314. {
  315. $aMoreInfo = array();
  316. $aMoreInfo[] = "Column: <em>".$oAttDef->GetSQLExpr()."</em>";
  317. $aMoreInfo[] = "Default: '".$oAttDef->GetDefaultValue()."'";
  318. $aMoreInfo[] = $oAttDef->IsNullAllowed() ? "Null allowed" : "Null NOT allowed";
  319. //$aMoreInfo[] = $oAttDef->DBGetUsedFields();
  320. $sMoreInfo .= implode(', ', $aMoreInfo);
  321. }
  322. if (is_object($oAllowedValuesDef)) $sAllowedValues = $oAllowedValuesDef->GetValuesDescription();
  323. else $sAllowedValues = '';
  324. $aDetails[] = array('code' => $oAttDef->GetCode(), 'type' => $sType, 'origin' => $sOrigin, 'label' => $oAttDef->GetLabel(), 'description' => $sValue, 'values' => $sAllowedValues, 'moreinfo' => $sMoreInfo);
  325. }
  326. $oPage->SetCurrentTab('Attributes');
  327. $aConfig = array( 'code' => array('label' => 'Attribute code', 'description' => 'Code of this attribute'),
  328. 'label' => array('label' => 'Label', 'description' => 'Label of this attribute'),
  329. 'type' => array('label' => 'Type', 'description' => 'Data type of this attribute'),
  330. 'origin' => array('label' => 'Origin', 'description' => 'The base class for this attribute'),
  331. 'description' => array('label' => 'Description', 'description' => 'Description of this attribute'),
  332. 'values' => array('label' => 'Allowed Values', 'description' => 'Restrictions on the possible values for this attribute'),
  333. 'moreinfo' => array('label' => 'More info', 'description' => 'More info for the fields related to a Database field'),
  334. );
  335. $oPage->table($aConfig, $aDetails);
  336. // List the search criteria for this object
  337. $aDetails = array();
  338. foreach (MetaModel::GetClassFilterDefs($sClass) as $sFilterCode => $oFilterDef)
  339. {
  340. $aOpDescs = array();
  341. foreach ($oFilterDef->GetOperators() as $sOpCode => $sOpDescription)
  342. {
  343. $sIsTheLooser = ($sOpCode == $oFilterDef->GetLooseOperator()) ? " (loose search)" : "";
  344. $aOpDescs[] = "$sOpCode ($sOpDescription)$sIsTheLooser";
  345. }
  346. $aDetails[] = array( 'code' => $sFilterCode, 'description' => $oFilterDef->GetLabel(),'operators' => implode(" / ", $aOpDescs));
  347. }
  348. $oPage->SetCurrentTab('Search criteria');
  349. $aConfig = array( 'code' => array('label' => 'Filter code', 'description' => 'Code of this search criteria'),
  350. 'description' => array('label' => 'Description', 'description' => 'Description of this search criteria'),
  351. 'operators' => array('label' => 'Available operators', 'description' => 'Possible operators for this search criteria')
  352. );
  353. $oPage->table($aConfig, $aDetails);
  354. $oPage->SetCurrentTab('Child classes');
  355. DisplaySubclasses($oPage, $sClass);
  356. $oPage->SetCurrentTab('Referencing classes');
  357. DisplayReferencingClasses($oPage, $sClass);
  358. $oPage->SetCurrentTab('Related classes');
  359. DisplayRelatedClasses($oPage, $sClass);
  360. $oPage->SetCurrentTab('Lifecycle');
  361. DisplayLifecycle($oPage, $sClass);
  362. $oPage->SetCurrentTab();
  363. $oPage->SetCurrentTabContainer();
  364. }
  365. /**
  366. * Display the details of a given relation (e.g. "impacts")
  367. */
  368. function DisplayRelationDetails($oPage, $sRelCode)
  369. {
  370. $sDesc = MetaModel::GetRelationProperty($sRelCode, 'description');
  371. $sVerbDown = MetaModel::GetRelationProperty($sRelCode, 'verb_down');
  372. $sVerbUp = MetaModel::GetRelationProperty($sRelCode, 'verb_up');
  373. $oPage->add("<h1>Relation <em>$sRelCode</em> ($sDesc)</h1>");
  374. $oPage->p("Down: $sVerbDown");
  375. $oPage->p("Up: $sVerbUp");
  376. $oPage->add("<ul id=\"RelationshipDetails\" class=\"treeview\">\n");
  377. foreach(MetaModel::GetClasses() as $sClass)
  378. {
  379. $aRelQueries = MetaModel::EnumRelationQueries($sClass, $sRelCode);
  380. if (count($aRelQueries) > 0)
  381. {
  382. $oPage->add("<li>class ".MakeClassHLink($sClass)."\n");
  383. $oPage->add("<ul>\n");
  384. foreach ($aRelQueries as $sRelKey => $aQuery)
  385. {
  386. $sQuery = $aQuery['sQuery'];
  387. $bPropagate = $aQuery['bPropagate'] ? "Propagate" : "Do not propagate";
  388. $iDistance = $aQuery['iDistance'];
  389. $oPage->add("<li>$sRelKey: $bPropagate ($iDistance) ".DBObjectSearch::SibuSQLAsHtml($sQuery)."</li>\n");
  390. }
  391. $oPage->add("</ul>\n");
  392. $oPage->add("</li>\n");
  393. }
  394. }
  395. $oPage->add_ready_script('$("#RelationshipDetails").treeview();');
  396. }
  397. require_once('../application/loginwebpage.class.inc.php');
  398. login_web_page::DoLogin(); // Check user rights and prompt if needed
  399. // Display the menu on the left
  400. $oContext = new UserContext();
  401. $oAppContext = new ApplicationContext();
  402. $iActiveNodeId = utils::ReadParam('menu', -1);
  403. $currentOrganization = utils::ReadParam('org_id', 1);
  404. $operation = utils::ReadParam('operation', '');
  405. $oPage = new iTopWebPage("iTop objects schema", $currentOrganization);
  406. $oPage->no_cache();
  407. $operation = utils::ReadParam('operation', '');
  408. switch($operation)
  409. {
  410. case 'details_class':
  411. $sClass = utils::ReadParam('class', 'logRealObject');
  412. DisplayClassDetails($oPage, $sClass);
  413. break;
  414. case 'details_relation':
  415. $sRelCode = utils::ReadParam('relcode', '');
  416. DisplayRelationDetails($oPage, $sRelCode);
  417. break;
  418. case 'details':
  419. $oPage->p('operation=details has been deprecated, please use details_class');
  420. break;
  421. case 'list':
  422. default:
  423. DisplayClassesList($oPage);
  424. }
  425. $oPage->output();
  426. ?>