cmdbchangeop.class.inc.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413
  1. <?php
  2. /**
  3. * Various atomic change operations, to be tracked
  4. *
  5. * @package iTopORM
  6. * @author Romain Quetiez <romainquetiez@yahoo.fr>
  7. * @author Denis Flaven <denisflave@free.fr>
  8. * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
  9. * @link www.itop.com
  10. * @since 1.0
  11. * @version 1.1.1.1 $
  12. */
  13. class CMDBChangeOp extends DBObject
  14. {
  15. public static function Init()
  16. {
  17. $aParams = array
  18. (
  19. "category" => "core/cmdb",
  20. "key_type" => "autoincrement",
  21. "key_label" => "",
  22. "name_attcode" => "change",
  23. "state_attcode" => "",
  24. "reconc_keys" => array(),
  25. "db_table" => "priv_changeop",
  26. "db_key_field" => "id",
  27. "db_finalclass_field" => "optype",
  28. );
  29. MetaModel::Init_Params($aParams);
  30. //MetaModel::Init_InheritAttributes();
  31. MetaModel::Init_AddAttribute(new AttributeExternalKey("change", array("allowed_values"=>null, "sql"=>"changeid", "targetclass"=>"CMDBChange", "is_null_allowed"=>false, "on_target_delete"=>DEL_MANUAL, "depends_on"=>array())));
  32. MetaModel::Init_AddAttribute(new AttributeExternalField("date", array("allowed_values"=>null, "extkey_attcode"=>"change", "target_attcode"=>"date")));
  33. MetaModel::Init_AddAttribute(new AttributeExternalField("userinfo", array("allowed_values"=>null, "extkey_attcode"=>"change", "target_attcode"=>"userinfo")));
  34. MetaModel::Init_AddAttribute(new AttributeString("objclass", array("allowed_values"=>null, "sql"=>"objclass", "default_value"=>"", "is_null_allowed"=>false, "depends_on"=>array())));
  35. MetaModel::Init_AddAttribute(new AttributeString("objkey", array("allowed_values"=>null, "sql"=>"objkey", "default_value"=>"", "is_null_allowed"=>false, "depends_on"=>array())));
  36. MetaModel::Init_AddFilterFromAttribute("objclass");
  37. MetaModel::Init_AddFilterFromAttribute("objkey");
  38. MetaModel::Init_AddFilterFromAttribute("date");
  39. MetaModel::Init_AddFilterFromAttribute("userinfo");
  40. MetaModel::Init_SetZListItems('details', array('change', 'date', 'userinfo')); // Attributes to be displayed for the complete details
  41. MetaModel::Init_SetZListItems('list', array('change', 'date', 'userinfo')); // Attributes to be displayed for the complete details
  42. }
  43. /**
  44. * Describe (as a text string) the modifications corresponding to this change
  45. */
  46. public function GetDescription()
  47. {
  48. return '';
  49. }
  50. }
  51. /**
  52. * Record the creation of an object
  53. *
  54. * @package iTopORM
  55. * @author Romain Quetiez <romainquetiez@yahoo.fr>
  56. * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
  57. * @link www.itop.com
  58. * @since 1.0
  59. * @version $itopversion$
  60. */
  61. class CMDBChangeOpCreate extends CMDBChangeOp
  62. {
  63. public static function Init()
  64. {
  65. $aParams = array
  66. (
  67. "category" => "core/cmdb",
  68. "key_type" => "",
  69. "key_label" => "",
  70. "name_attcode" => "change",
  71. "state_attcode" => "",
  72. "reconc_keys" => array(),
  73. "db_table" => "priv_changeop_create",
  74. "db_key_field" => "id",
  75. "db_finalclass_field" => "",
  76. );
  77. MetaModel::Init_Params($aParams);
  78. MetaModel::Init_InheritAttributes();
  79. MetaModel::Init_InheritFilters();
  80. }
  81. /**
  82. * Describe (as a text string) the modifications corresponding to this change
  83. */
  84. public function GetDescription()
  85. {
  86. return 'Object created';
  87. }
  88. }
  89. /**
  90. * Record the deletion of an object
  91. *
  92. * @package iTopORM
  93. * @author Romain Quetiez <romainquetiez@yahoo.fr>
  94. * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
  95. * @link www.itop.com
  96. * @since 1.0
  97. * @version $itopversion$
  98. */
  99. class CMDBChangeOpDelete extends CMDBChangeOp
  100. {
  101. public static function Init()
  102. {
  103. $aParams = array
  104. (
  105. "category" => "core/cmdb",
  106. "key_type" => "",
  107. "key_label" => "",
  108. "name_attcode" => "change",
  109. "state_attcode" => "",
  110. "reconc_keys" => array(),
  111. "db_table" => "priv_changeop_delete",
  112. "db_key_field" => "id",
  113. "db_finalclass_field" => "",
  114. );
  115. MetaModel::Init_Params($aParams);
  116. MetaModel::Init_InheritAttributes();
  117. MetaModel::Init_InheritFilters();
  118. }
  119. /**
  120. * Describe (as a text string) the modifications corresponding to this change
  121. */
  122. public function GetDescription()
  123. {
  124. return 'Object deleted';
  125. }
  126. }
  127. /**
  128. * Record the modification of an attribute (abstract)
  129. *
  130. * @package iTopORM
  131. * @author Romain Quetiez <romainquetiez@yahoo.fr>
  132. * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
  133. * @link www.itop.com
  134. * @since 1.0
  135. * @version $itopversion$
  136. */
  137. class CMDBChangeOpSetAttribute extends CMDBChangeOp
  138. {
  139. public static function Init()
  140. {
  141. $aParams = array
  142. (
  143. "category" => "core/cmdb",
  144. "key_type" => "",
  145. "key_label" => "",
  146. "name_attcode" => "change",
  147. "state_attcode" => "",
  148. "reconc_keys" => array(),
  149. "db_table" => "priv_changeop_setatt",
  150. "db_key_field" => "id",
  151. "db_finalclass_field" => "",
  152. );
  153. MetaModel::Init_Params($aParams);
  154. MetaModel::Init_InheritAttributes();
  155. MetaModel::Init_AddAttribute(new AttributeString("attcode", array("allowed_values"=>null, "sql"=>"attcode", "default_value"=>"", "is_null_allowed"=>false, "depends_on"=>array())));
  156. MetaModel::Init_InheritFilters();
  157. MetaModel::Init_AddFilterFromAttribute("attcode");
  158. // Display lists
  159. MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details
  160. MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list
  161. }
  162. }
  163. /**
  164. * Record the modification of a scalar attribute
  165. *
  166. * @package iTopORM
  167. * @author Romain Quetiez <romainquetiez@yahoo.fr>
  168. * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
  169. * @link www.itop.com
  170. * @since 1.0
  171. * @version $itopversion$
  172. */
  173. class CMDBChangeOpSetAttributeScalar extends CMDBChangeOpSetAttribute
  174. {
  175. public static function Init()
  176. {
  177. $aParams = array
  178. (
  179. "category" => "core/cmdb",
  180. "key_type" => "",
  181. "key_label" => "",
  182. "name_attcode" => "change",
  183. "state_attcode" => "",
  184. "reconc_keys" => array(),
  185. "db_table" => "priv_changeop_setatt_scalar",
  186. "db_key_field" => "id",
  187. "db_finalclass_field" => "",
  188. );
  189. MetaModel::Init_Params($aParams);
  190. MetaModel::Init_InheritAttributes();
  191. MetaModel::Init_AddAttribute(new AttributeString("oldvalue", array("allowed_values"=>null, "sql"=>"oldvalue", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array())));
  192. MetaModel::Init_AddAttribute(new AttributeString("newvalue", array("allowed_values"=>null, "sql"=>"newvalue", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array())));
  193. MetaModel::Init_InheritFilters();
  194. MetaModel::Init_AddFilterFromAttribute("oldvalue");
  195. MetaModel::Init_AddFilterFromAttribute("newvalue");
  196. // Display lists
  197. MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode', 'oldvalue', 'newvalue')); // Attributes to be displayed for the complete details
  198. MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode', 'oldvalue', 'newvalue')); // Attributes to be displayed for a list
  199. }
  200. /**
  201. * Describe (as a text string) the modifications corresponding to this change
  202. */
  203. public function GetDescription()
  204. {
  205. // Temporary, until we change the options of GetDescription() -needs a more global revision
  206. $bIsHtml = true;
  207. $sResult = '';
  208. $oTargetObjectClass = $this->Get('objclass');
  209. $oTargetObjectKey = $this->Get('objkey');
  210. $oTargetSearch = new DBObjectSearch($oTargetObjectClass);
  211. $oTargetSearch->AddCondition('id', $oTargetObjectKey);
  212. $oMonoObjectSet = new DBObjectSet($oTargetSearch);
  213. if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES)
  214. {
  215. $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode'));
  216. $sAttName = $oAttDef->GetLabel();
  217. $sNewValue = $this->Get('newvalue');
  218. $sOldValue = $this->Get('oldvalue');
  219. if ( (($oAttDef->GetType() == 'String') || ($oAttDef->GetType() == 'Text')) &&
  220. (strlen($sNewValue) > strlen($sOldValue)) )
  221. {
  222. // Check if some text was not appended to the field
  223. if (substr($sNewValue,0, strlen($sOldValue)) == $sOldValue) // Text added at the end
  224. {
  225. $sDelta = substr($sNewValue, strlen($sOldValue));
  226. $sResult = "$sDelta appended to $sAttName";
  227. }
  228. else if (substr($sNewValue, -strlen($sOldValue)) == $sOldValue) // Text added at the beginning
  229. {
  230. $sDelta = substr($sNewValue, 0, strlen($sNewValue) - strlen($sOldValue));
  231. $sResult = "$sDelta appended to $sAttName";
  232. }
  233. else
  234. {
  235. $sResult = "$sAttName set to $sNewValue (previous value: $sOldValue)";
  236. }
  237. }
  238. elseif($bIsHtml && $oAttDef->IsExternalKey())
  239. {
  240. $sTargetClass = $oAttDef->GetTargetClass();
  241. $sFrom = MetaModel::GetHyperLink($sTargetClass, $sOldValue);
  242. $sTo = MetaModel::GetHyperLink($sTargetClass, $sNewValue);
  243. $sResult = "$sAttName set to $sTo (previous: $sFrom)";
  244. }
  245. elseif ($oAttDef instanceOf AttributeBlob)
  246. {
  247. $sResult = "#@# Issue... found an attribute for which other type of tracking should be made";
  248. }
  249. else
  250. {
  251. $sResult = "$sAttName set to $sNewValue (previous value: $sOldValue)";
  252. }
  253. }
  254. return $sResult;
  255. }
  256. }
  257. /**
  258. * Record the modification of a blob
  259. *
  260. * @package iTopORM
  261. * @author Romain Quetiez <romainquetiez@yahoo.fr>
  262. * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
  263. * @link www.itop.com
  264. * @since 1.0
  265. * @version $itopversion$
  266. */
  267. class CMDBChangeOpSetAttributeBlob extends CMDBChangeOpSetAttribute
  268. {
  269. public static function Init()
  270. {
  271. $aParams = array
  272. (
  273. "category" => "core/cmdb",
  274. "key_type" => "",
  275. "key_label" => "",
  276. "name_attcode" => "change",
  277. "state_attcode" => "",
  278. "reconc_keys" => array(),
  279. "db_table" => "priv_changeop_setatt_data",
  280. "db_key_field" => "id",
  281. "db_finalclass_field" => "",
  282. );
  283. MetaModel::Init_Params($aParams);
  284. MetaModel::Init_InheritAttributes();
  285. MetaModel::Init_AddAttribute(new AttributeBlob("prevdata", array("depends_on"=>array())));
  286. MetaModel::Init_InheritFilters();
  287. // Display lists
  288. MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details
  289. MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list
  290. }
  291. /**
  292. * Describe (as a text string) the modifications corresponding to this change
  293. */
  294. public function GetDescription()
  295. {
  296. // Temporary, until we change the options of GetDescription() -needs a more global revision
  297. $bIsHtml = true;
  298. $sResult = '';
  299. $oTargetObjectClass = $this->Get('objclass');
  300. $oTargetObjectKey = $this->Get('objkey');
  301. $oTargetSearch = new DBObjectSearch($oTargetObjectClass);
  302. $oTargetSearch->AddCondition('id', $oTargetObjectKey);
  303. $oMonoObjectSet = new DBObjectSet($oTargetSearch);
  304. if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES)
  305. {
  306. $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode'));
  307. $sAttName = $oAttDef->GetLabel();
  308. $oPrevDoc = $this->Get('prevdata');
  309. $sDocView = $oPrevDoc->GetAsHtml();
  310. $sDocView .= "<br/>Open in New Window: ".$oPrevDoc->GetDisplayLink(get_class($this), $this->GetKey(), 'prevdata').", \n";
  311. $sDocView .= "Download: ".$oPrevDoc->GetDownloadLink(get_class($this), $this->GetKey(), 'prevdata')."\n";
  312. //$sDocView = $oPrevDoc->GetDisplayInline(get_class($this), $this->GetKey(), 'prevdata');
  313. $sResult = "$sAttName changed, previous value: $sDocView";
  314. }
  315. return $sResult;
  316. }
  317. }
  318. /**
  319. * Record the modification of a multiline string (text)
  320. *
  321. * @package iTopORM
  322. * @author Romain Quetiez <romainquetiez@yahoo.fr>
  323. * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
  324. * @link www.itop.com
  325. * @since 1.0
  326. * @version $itopversion$
  327. */
  328. class CMDBChangeOpSetAttributeText extends CMDBChangeOpSetAttribute
  329. {
  330. public static function Init()
  331. {
  332. $aParams = array
  333. (
  334. "category" => "core/cmdb",
  335. "key_type" => "",
  336. "key_label" => "",
  337. "name_attcode" => "change",
  338. "state_attcode" => "",
  339. "reconc_keys" => array(),
  340. "db_table" => "priv_changeop_setatt_text",
  341. "db_key_field" => "id",
  342. "db_finalclass_field" => "",
  343. );
  344. MetaModel::Init_Params($aParams);
  345. MetaModel::Init_InheritAttributes();
  346. MetaModel::Init_AddAttribute(new AttributeText("prevdata", array("allowed_values"=>null, "sql"=>"prevdata", "default_value"=>"", "is_null_allowed"=>true, "depends_on"=>array())));
  347. MetaModel::Init_InheritFilters();
  348. // Display lists
  349. MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details
  350. MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list
  351. }
  352. /**
  353. * Describe (as a text string) the modifications corresponding to this change
  354. */
  355. public function GetDescription()
  356. {
  357. // Temporary, until we change the options of GetDescription() -needs a more global revision
  358. $bIsHtml = true;
  359. $sResult = '';
  360. $oTargetObjectClass = $this->Get('objclass');
  361. $oTargetObjectKey = $this->Get('objkey');
  362. $oTargetSearch = new DBObjectSearch($oTargetObjectClass);
  363. $oTargetSearch->AddCondition('id', $oTargetObjectKey);
  364. $oMonoObjectSet = new DBObjectSet($oTargetSearch);
  365. if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES)
  366. {
  367. $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode'));
  368. $sAttName = $oAttDef->GetLabel();
  369. $sTextView = '<div>'.$this->GetAsHtml('prevdata').'</div>';
  370. //$sDocView = $oPrevDoc->GetDisplayInline(get_class($this), $this->GetKey(), 'prevdata');
  371. $sResult = "$sAttName changed, previous value: $sTextView";
  372. }
  373. return $sResult;
  374. }
  375. }
  376. ?>