cmdbchangeop.class.inc.php 14 KB

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