cmdbchangeop.class.inc.php 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866
  1. <?php
  2. // Copyright (C) 2010-2013 Combodo SARL
  3. //
  4. // This file is part of iTop.
  5. //
  6. // iTop is free software; you can redistribute it and/or modify
  7. // it under the terms of the GNU Affero General Public License as published by
  8. // the Free Software Foundation, either version 3 of the License, or
  9. // (at your option) any later version.
  10. //
  11. // iTop is distributed in the hope that it will be useful,
  12. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. // GNU Affero General Public License for more details.
  15. //
  16. // You should have received a copy of the GNU Affero General Public License
  17. // along with iTop. If not, see <http://www.gnu.org/licenses/>
  18. /**
  19. * Persistent classes (internal) : cmdbChangeOp and derived
  20. *
  21. * @copyright Copyright (C) 2010-2012 Combodo SARL
  22. * @license http://opensource.org/licenses/AGPL-3.0
  23. */
  24. /**
  25. * Various atomic change operations, to be tracked
  26. *
  27. * @package iTopORM
  28. */
  29. class CMDBChangeOp extends DBObject
  30. {
  31. public static function Init()
  32. {
  33. $aParams = array
  34. (
  35. "category" => "core/cmdb",
  36. "key_type" => "autoincrement",
  37. "name_attcode" => "change",
  38. "state_attcode" => "",
  39. "reconc_keys" => array(),
  40. "db_table" => "priv_changeop",
  41. "db_key_field" => "id",
  42. "db_finalclass_field" => "optype",
  43. 'indexes' => array(
  44. array('objclass', 'objkey'),
  45. )
  46. );
  47. MetaModel::Init_Params($aParams);
  48. //MetaModel::Init_InheritAttributes();
  49. 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())));
  50. MetaModel::Init_AddAttribute(new AttributeExternalField("date", array("allowed_values"=>null, "extkey_attcode"=>"change", "target_attcode"=>"date")));
  51. MetaModel::Init_AddAttribute(new AttributeExternalField("userinfo", array("allowed_values"=>null, "extkey_attcode"=>"change", "target_attcode"=>"userinfo")));
  52. MetaModel::Init_AddAttribute(new AttributeString("objclass", array("allowed_values"=>null, "sql"=>"objclass", "default_value"=>"", "is_null_allowed"=>false, "depends_on"=>array())));
  53. MetaModel::Init_AddAttribute(new AttributeObjectKey("objkey", array("allowed_values"=>null, "class_attcode"=>"objclass", "sql"=>"objkey", "is_null_allowed"=>false, "depends_on"=>array())));
  54. MetaModel::Init_SetZListItems('details', array('change', 'date', 'userinfo')); // Attributes to be displayed for the complete details
  55. MetaModel::Init_SetZListItems('list', array('change', 'date', 'userinfo')); // Attributes to be displayed for the complete details
  56. }
  57. /**
  58. * Describe (as a text string) the modifications corresponding to this change
  59. */
  60. public function GetDescription()
  61. {
  62. return '';
  63. }
  64. /**
  65. * Safety net: in case the change is not given, let's guarantee that it will
  66. * be set to the current ongoing change (or create a new one)
  67. */
  68. protected function OnInsert()
  69. {
  70. if ($this->Get('change') <= 0)
  71. {
  72. $this->Set('change', CMDBObject::GetCurrentChange());
  73. }
  74. parent::OnInsert();
  75. }
  76. }
  77. /**
  78. * Record the creation of an object
  79. *
  80. * @package iTopORM
  81. */
  82. class CMDBChangeOpCreate extends CMDBChangeOp
  83. {
  84. public static function Init()
  85. {
  86. $aParams = array
  87. (
  88. "category" => "core/cmdb",
  89. "key_type" => "",
  90. "name_attcode" => "change",
  91. "state_attcode" => "",
  92. "reconc_keys" => array(),
  93. "db_table" => "priv_changeop_create",
  94. "db_key_field" => "id",
  95. "db_finalclass_field" => "",
  96. );
  97. MetaModel::Init_Params($aParams);
  98. MetaModel::Init_InheritAttributes();
  99. }
  100. /**
  101. * Describe (as a text string) the modifications corresponding to this change
  102. */
  103. public function GetDescription()
  104. {
  105. return Dict::S('Change:ObjectCreated');
  106. }
  107. }
  108. /**
  109. * Record the deletion of an object
  110. *
  111. * @package iTopORM
  112. */
  113. class CMDBChangeOpDelete extends CMDBChangeOp
  114. {
  115. public static function Init()
  116. {
  117. $aParams = array
  118. (
  119. "category" => "core/cmdb",
  120. "key_type" => "",
  121. "name_attcode" => "change",
  122. "state_attcode" => "",
  123. "reconc_keys" => array(),
  124. "db_table" => "priv_changeop_delete",
  125. "db_key_field" => "id",
  126. "db_finalclass_field" => "",
  127. );
  128. MetaModel::Init_Params($aParams);
  129. MetaModel::Init_InheritAttributes();
  130. // Final class of the object (objclass must be set to the root class for efficiency purposes)
  131. MetaModel::Init_AddAttribute(new AttributeString("fclass", array("allowed_values"=>null, "sql"=>"fclass", "default_value"=>"", "is_null_allowed"=>false, "depends_on"=>array())));
  132. // Last friendly name of the object
  133. MetaModel::Init_AddAttribute(new AttributeString("fname", array("allowed_values"=>null, "sql"=>"fname", "default_value"=>"", "is_null_allowed"=>true, "depends_on"=>array())));
  134. }
  135. /**
  136. * Describe (as a text string) the modifications corresponding to this change
  137. */
  138. public function GetDescription()
  139. {
  140. return Dict::S('Change:ObjectDeleted');
  141. }
  142. }
  143. /**
  144. * Record the modification of an attribute (abstract)
  145. *
  146. * @package iTopORM
  147. */
  148. class CMDBChangeOpSetAttribute extends CMDBChangeOp
  149. {
  150. public static function Init()
  151. {
  152. $aParams = array
  153. (
  154. "category" => "core/cmdb",
  155. "key_type" => "",
  156. "name_attcode" => "change",
  157. "state_attcode" => "",
  158. "reconc_keys" => array(),
  159. "db_table" => "priv_changeop_setatt",
  160. "db_key_field" => "id",
  161. "db_finalclass_field" => "",
  162. );
  163. MetaModel::Init_Params($aParams);
  164. MetaModel::Init_InheritAttributes();
  165. MetaModel::Init_AddAttribute(new AttributeString("attcode", array("allowed_values"=>null, "sql"=>"attcode", "default_value"=>"", "is_null_allowed"=>false, "depends_on"=>array())));
  166. // Display lists
  167. MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details
  168. MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list
  169. }
  170. }
  171. /**
  172. * Record the modification of a scalar attribute
  173. *
  174. * @package iTopORM
  175. */
  176. class CMDBChangeOpSetAttributeScalar extends CMDBChangeOpSetAttribute
  177. {
  178. public static function Init()
  179. {
  180. $aParams = array
  181. (
  182. "category" => "core/cmdb",
  183. "key_type" => "",
  184. "name_attcode" => "change",
  185. "state_attcode" => "",
  186. "reconc_keys" => array(),
  187. "db_table" => "priv_changeop_setatt_scalar",
  188. "db_key_field" => "id",
  189. "db_finalclass_field" => "",
  190. );
  191. MetaModel::Init_Params($aParams);
  192. MetaModel::Init_InheritAttributes();
  193. MetaModel::Init_AddAttribute(new AttributeString("oldvalue", array("allowed_values"=>null, "sql"=>"oldvalue", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array())));
  194. MetaModel::Init_AddAttribute(new AttributeString("newvalue", array("allowed_values"=>null, "sql"=>"newvalue", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array())));
  195. // Display lists
  196. MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode', 'oldvalue', 'newvalue')); // Attributes to be displayed for the complete details
  197. MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode', 'oldvalue', 'newvalue')); // Attributes to be displayed for a list
  198. }
  199. /**
  200. * Describe (as a text string) the modifications corresponding to this change
  201. */
  202. public function GetDescription()
  203. {
  204. $sResult = '';
  205. $oTargetObjectClass = $this->Get('objclass');
  206. $oTargetObjectKey = $this->Get('objkey');
  207. $oTargetSearch = new DBObjectSearch($oTargetObjectClass);
  208. $oTargetSearch->AddCondition('id', $oTargetObjectKey, '=');
  209. $oMonoObjectSet = new DBObjectSet($oTargetSearch);
  210. if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES)
  211. {
  212. if (!MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) return ''; // Protects against renamed attributes...
  213. $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode'));
  214. $sAttName = $oAttDef->GetLabel();
  215. $sNewValue = $this->Get('newvalue');
  216. $sOldValue = $this->Get('oldvalue');
  217. $sResult = $oAttDef->DescribeChangeAsHTML($sOldValue, $sNewValue);
  218. }
  219. return $sResult;
  220. }
  221. }
  222. /**
  223. * Record the modification of a blob
  224. *
  225. * @package iTopORM
  226. */
  227. class CMDBChangeOpSetAttributeBlob extends CMDBChangeOpSetAttribute
  228. {
  229. public static function Init()
  230. {
  231. $aParams = array
  232. (
  233. "category" => "core/cmdb",
  234. "key_type" => "",
  235. "name_attcode" => "change",
  236. "state_attcode" => "",
  237. "reconc_keys" => array(),
  238. "db_table" => "priv_changeop_setatt_data",
  239. "db_key_field" => "id",
  240. "db_finalclass_field" => "",
  241. );
  242. MetaModel::Init_Params($aParams);
  243. MetaModel::Init_InheritAttributes();
  244. MetaModel::Init_AddAttribute(new AttributeBlob("prevdata", array("depends_on"=>array())));
  245. // Display lists
  246. MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details
  247. MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list
  248. }
  249. /**
  250. * Describe (as a text string) the modifications corresponding to this change
  251. */
  252. public function GetDescription()
  253. {
  254. // Temporary, until we change the options of GetDescription() -needs a more global revision
  255. $bIsHtml = true;
  256. $sResult = '';
  257. $oTargetObjectClass = $this->Get('objclass');
  258. $oTargetObjectKey = $this->Get('objkey');
  259. $oTargetSearch = new DBObjectSearch($oTargetObjectClass);
  260. $oTargetSearch->AddCondition('id', $oTargetObjectKey, '=');
  261. $oMonoObjectSet = new DBObjectSet($oTargetSearch);
  262. if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES)
  263. {
  264. if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode')))
  265. {
  266. $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode'));
  267. $sAttName = $oAttDef->GetLabel();
  268. }
  269. else
  270. {
  271. // The attribute was renamed or removed from the object ?
  272. $sAttName = $this->Get('attcode');
  273. }
  274. $oPrevDoc = $this->Get('prevdata');
  275. $sDocView = $oPrevDoc->GetAsHtml();
  276. $sDocView .= "<br/>".Dict::Format('UI:OpenDocumentInNewWindow_',$oPrevDoc->GetDisplayLink(get_class($this), $this->GetKey(), 'prevdata')).", \n";
  277. $sDocView .= Dict::Format('UI:DownloadDocument_', $oPrevDoc->GetDownloadLink(get_class($this), $this->GetKey(), 'prevdata'))."\n";
  278. //$sDocView = $oPrevDoc->GetDisplayInline(get_class($this), $this->GetKey(), 'prevdata');
  279. $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sDocView);
  280. }
  281. return $sResult;
  282. }
  283. }
  284. /**
  285. * Safely record the modification of one way encrypted password
  286. */
  287. class CMDBChangeOpSetAttributeOneWayPassword extends CMDBChangeOpSetAttribute
  288. {
  289. public static function Init()
  290. {
  291. $aParams = array
  292. (
  293. "category" => "core/cmdb",
  294. "key_type" => "",
  295. "name_attcode" => "change",
  296. "state_attcode" => "",
  297. "reconc_keys" => array(),
  298. "db_table" => "priv_changeop_setatt_pwd",
  299. "db_key_field" => "id",
  300. "db_finalclass_field" => "",
  301. );
  302. MetaModel::Init_Params($aParams);
  303. MetaModel::Init_InheritAttributes();
  304. MetaModel::Init_AddAttribute(new AttributeOneWayPassword("prev_pwd", array("sql" => 'data', "default_value" => '', "is_null_allowed"=> true, "allowed_values" => null, "depends_on"=>array())));
  305. // Display lists
  306. MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details
  307. MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list
  308. }
  309. /**
  310. * Describe (as a text string) the modifications corresponding to this change
  311. */
  312. public function GetDescription()
  313. {
  314. // Temporary, until we change the options of GetDescription() -needs a more global revision
  315. $bIsHtml = true;
  316. $sResult = '';
  317. $oTargetObjectClass = $this->Get('objclass');
  318. $oTargetObjectKey = $this->Get('objkey');
  319. $oTargetSearch = new DBObjectSearch($oTargetObjectClass);
  320. $oTargetSearch->AddCondition('id', $oTargetObjectKey, '=');
  321. $oMonoObjectSet = new DBObjectSet($oTargetSearch);
  322. if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES)
  323. {
  324. if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode')))
  325. {
  326. $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode'));
  327. $sAttName = $oAttDef->GetLabel();
  328. }
  329. else
  330. {
  331. // The attribute was renamed or removed from the object ?
  332. $sAttName = $this->Get('attcode');
  333. }
  334. $sResult = Dict::Format('Change:AttName_Changed', $sAttName);
  335. }
  336. return $sResult;
  337. }
  338. }
  339. /**
  340. * Safely record the modification of an encrypted field
  341. */
  342. class CMDBChangeOpSetAttributeEncrypted extends CMDBChangeOpSetAttribute
  343. {
  344. public static function Init()
  345. {
  346. $aParams = array
  347. (
  348. "category" => "core/cmdb",
  349. "key_type" => "",
  350. "name_attcode" => "change",
  351. "state_attcode" => "",
  352. "reconc_keys" => array(),
  353. "db_table" => "priv_changeop_setatt_encrypted",
  354. "db_key_field" => "id",
  355. "db_finalclass_field" => "",
  356. );
  357. MetaModel::Init_Params($aParams);
  358. MetaModel::Init_InheritAttributes();
  359. MetaModel::Init_AddAttribute(new AttributeEncryptedString("prevstring", array("sql" => 'data', "default_value" => '', "is_null_allowed"=> true, "allowed_values" => null, "depends_on"=>array())));
  360. // Display lists
  361. MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details
  362. MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list
  363. }
  364. /**
  365. * Describe (as a text string) the modifications corresponding to this change
  366. */
  367. public function GetDescription()
  368. {
  369. // Temporary, until we change the options of GetDescription() -needs a more global revision
  370. $bIsHtml = true;
  371. $sResult = '';
  372. $oTargetObjectClass = $this->Get('objclass');
  373. $oTargetObjectKey = $this->Get('objkey');
  374. $oTargetSearch = new DBObjectSearch($oTargetObjectClass);
  375. $oTargetSearch->AddCondition('id', $oTargetObjectKey, '=');
  376. $oMonoObjectSet = new DBObjectSet($oTargetSearch);
  377. if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES)
  378. {
  379. if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode')))
  380. {
  381. $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode'));
  382. $sAttName = $oAttDef->GetLabel();
  383. }
  384. else
  385. {
  386. // The attribute was renamed or removed from the object ?
  387. $sAttName = $this->Get('attcode');
  388. }
  389. $sPrevString = $this->Get('prevstring');
  390. $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sPrevString);
  391. }
  392. return $sResult;
  393. }
  394. }
  395. /**
  396. * Record the modification of a multiline string (text)
  397. *
  398. * @package iTopORM
  399. */
  400. class CMDBChangeOpSetAttributeText extends CMDBChangeOpSetAttribute
  401. {
  402. public static function Init()
  403. {
  404. $aParams = array
  405. (
  406. "category" => "core/cmdb",
  407. "key_type" => "",
  408. "name_attcode" => "change",
  409. "state_attcode" => "",
  410. "reconc_keys" => array(),
  411. "db_table" => "priv_changeop_setatt_text",
  412. "db_key_field" => "id",
  413. "db_finalclass_field" => "",
  414. );
  415. MetaModel::Init_Params($aParams);
  416. MetaModel::Init_InheritAttributes();
  417. MetaModel::Init_AddAttribute(new AttributeText("prevdata", array("allowed_values"=>null, "sql"=>"prevdata", "default_value"=>"", "is_null_allowed"=>true, "depends_on"=>array())));
  418. // Display lists
  419. MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details
  420. MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list
  421. }
  422. /**
  423. * Describe (as a text string) the modifications corresponding to this change
  424. */
  425. public function GetDescription()
  426. {
  427. // Temporary, until we change the options of GetDescription() -needs a more global revision
  428. $bIsHtml = true;
  429. $sResult = '';
  430. $oTargetObjectClass = $this->Get('objclass');
  431. $oTargetObjectKey = $this->Get('objkey');
  432. $oTargetSearch = new DBObjectSearch($oTargetObjectClass);
  433. $oTargetSearch->AddCondition('id', $oTargetObjectKey, '=');
  434. $oMonoObjectSet = new DBObjectSet($oTargetSearch);
  435. if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES)
  436. {
  437. if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode')))
  438. {
  439. $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode'));
  440. $sAttName = $oAttDef->GetLabel();
  441. }
  442. else
  443. {
  444. // The attribute was renamed or removed from the object ?
  445. $sAttName = $this->Get('attcode');
  446. }
  447. $sTextView = '<div>'.$this->GetAsHtml('prevdata').'</div>';
  448. //$sDocView = $oPrevDoc->GetDisplayInline(get_class($this), $this->GetKey(), 'prevdata');
  449. $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sTextView);
  450. }
  451. return $sResult;
  452. }
  453. }
  454. /**
  455. * Record the modification of a multiline string (text)
  456. *
  457. * @package iTopORM
  458. */
  459. class CMDBChangeOpSetAttributeLongText extends CMDBChangeOpSetAttribute
  460. {
  461. public static function Init()
  462. {
  463. $aParams = array
  464. (
  465. "category" => "core/cmdb",
  466. "key_type" => "",
  467. "name_attcode" => "change",
  468. "state_attcode" => "",
  469. "reconc_keys" => array(),
  470. "db_table" => "priv_changeop_setatt_longtext",
  471. "db_key_field" => "id",
  472. "db_finalclass_field" => "",
  473. );
  474. MetaModel::Init_Params($aParams);
  475. MetaModel::Init_InheritAttributes();
  476. MetaModel::Init_AddAttribute(new AttributeLongText("prevdata", array("allowed_values"=>null, "sql"=>"prevdata", "default_value"=>"", "is_null_allowed"=>true, "depends_on"=>array())));
  477. // Display lists
  478. MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details
  479. MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list
  480. }
  481. /**
  482. * Describe (as a text string) the modifications corresponding to this change
  483. */
  484. public function GetDescription()
  485. {
  486. // Temporary, until we change the options of GetDescription() -needs a more global revision
  487. $bIsHtml = true;
  488. $sResult = '';
  489. $oTargetObjectClass = $this->Get('objclass');
  490. $oTargetObjectKey = $this->Get('objkey');
  491. $oTargetSearch = new DBObjectSearch($oTargetObjectClass);
  492. $oTargetSearch->AddCondition('id', $oTargetObjectKey, '=');
  493. $oMonoObjectSet = new DBObjectSet($oTargetSearch);
  494. if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES)
  495. {
  496. if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode')))
  497. {
  498. $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode'));
  499. $sAttName = $oAttDef->GetLabel();
  500. }
  501. else
  502. {
  503. // The attribute was renamed or removed from the object ?
  504. $sAttName = $this->Get('attcode');
  505. }
  506. $sTextView = '<div>'.$this->GetAsHtml('prevdata').'</div>';
  507. //$sDocView = $oPrevDoc->GetDisplayInline(get_class($this), $this->GetKey(), 'prevdata');
  508. $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sTextView);
  509. }
  510. return $sResult;
  511. }
  512. }
  513. /**
  514. * Record the modification of a caselog (text)
  515. * since the caselog itself stores the history
  516. * of its entries, there is no need to duplicate
  517. * the text here
  518. *
  519. * @package iTopORM
  520. */
  521. class CMDBChangeOpSetAttributeCaseLog extends CMDBChangeOpSetAttribute
  522. {
  523. public static function Init()
  524. {
  525. $aParams = array
  526. (
  527. "category" => "core/cmdb",
  528. "key_type" => "",
  529. "name_attcode" => "change",
  530. "state_attcode" => "",
  531. "reconc_keys" => array(),
  532. "db_table" => "priv_changeop_setatt_log",
  533. "db_key_field" => "id",
  534. "db_finalclass_field" => "",
  535. );
  536. MetaModel::Init_Params($aParams);
  537. MetaModel::Init_InheritAttributes();
  538. MetaModel::Init_AddAttribute(new AttributeInteger("lastentry", array("allowed_values"=>null, "sql"=>"lastentry", "default_value"=>0, "is_null_allowed"=>true, "depends_on"=>array())));
  539. // Display lists
  540. MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details
  541. MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list
  542. }
  543. /**
  544. * Describe (as a text string) the modifications corresponding to this change
  545. */
  546. public function GetDescription()
  547. {
  548. // Temporary, until we change the options of GetDescription() -needs a more global revision
  549. $bIsHtml = true;
  550. $sResult = '';
  551. $oTargetObjectClass = $this->Get('objclass');
  552. $oTargetObjectKey = $this->Get('objkey');
  553. $oTargetSearch = new DBObjectSearch($oTargetObjectClass);
  554. $oTargetSearch->AddCondition('id', $oTargetObjectKey, '=');
  555. $oMonoObjectSet = new DBObjectSet($oTargetSearch);
  556. if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES)
  557. {
  558. if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode')))
  559. {
  560. $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode'));
  561. $sAttName = $oAttDef->GetLabel();
  562. }
  563. else
  564. {
  565. // The attribute was renamed or removed from the object ?
  566. $sAttName = $this->Get('attcode');
  567. }
  568. $oObj = $oMonoObjectSet->Fetch();
  569. $oCaseLog = $oObj->Get($this->Get('attcode'));
  570. $iMaxVisibleLength = MetaModel::getConfig()->Get('max_history_case_log_entry_length', 0);
  571. $sTextEntry = str_replace(array("\r\n", "\n", "\r"), "<br/>", htmlentities($oCaseLog->GetEntryAt($this->Get('lastentry')), ENT_QUOTES, 'UTF-8'));
  572. if (($iMaxVisibleLength > 0) && (strlen($sTextEntry) > $iMaxVisibleLength))
  573. {
  574. if (function_exists('mb_strcut'))
  575. {
  576. // Safe with multi-byte strings
  577. $sBefore = mb_strcut($sTextEntry, 0, $iMaxVisibleLength);
  578. $sAfter = mb_strcut($sTextEntry, $iMaxVisibleLength);
  579. }
  580. else
  581. {
  582. // Let's hpe we have no multi-byte characters around the cuttting point...
  583. $sBefore = substr($sTextEntry, 0, $iMaxVisibleLength);
  584. $sAfter = substr($sTextEntry, $iMaxVisibleLength);
  585. }
  586. $sTextEntry = '<span class="case-log-history-entry">'.$sBefore.'<span class="case-log-history-entry-end">'.$sAfter.'<span class="case-log-history-entry-toggle ui-icon ui-icon-circle-minus"></span></span><span class="case-log-history-entry-more">...<span class="case-log-history-entry-toggle ui-icon ui-icon-circle-plus"></span></span></span>';
  587. }
  588. $sResult = Dict::Format('Change:AttName_EntryAdded', $sAttName, $sTextEntry);
  589. }
  590. return $sResult;
  591. }
  592. }
  593. /**
  594. * Record an action made by a plug-in
  595. *
  596. * @package iTopORM
  597. */
  598. class CMDBChangeOpPlugin extends CMDBChangeOp
  599. {
  600. public static function Init()
  601. {
  602. $aParams = array
  603. (
  604. "category" => "core/cmdb",
  605. "key_type" => "",
  606. "name_attcode" => "change",
  607. "state_attcode" => "",
  608. "reconc_keys" => array(),
  609. "db_table" => "priv_changeop_plugin",
  610. "db_key_field" => "id",
  611. "db_finalclass_field" => "",
  612. );
  613. MetaModel::Init_Params($aParams);
  614. MetaModel::Init_AddAttribute(new AttributeString("description", array("allowed_values"=>null, "sql"=>"description", "default_value"=>'', "is_null_allowed"=>false, "depends_on"=>array())));
  615. /* May be used later when implementing an extension mechanism that will allow the plug-ins to store some extra information and still degrades gracefully when the plug-in is desinstalled
  616. MetaModel::Init_AddAttribute(new AttributeString("extension_class", array("allowed_values"=>null, "sql"=>"extension_class", "default_value"=>'', "is_null_allowed"=>false, "depends_on"=>array())));
  617. MetaModel::Init_AddAttribute(new AttributeInteger("extension_id", array("allowed_values"=>null, "sql"=>"extension_id", "default_value"=>0, "is_null_allowed"=>false, "depends_on"=>array())));
  618. */
  619. MetaModel::Init_InheritAttributes();
  620. }
  621. /**
  622. * Describe (as a text string) the modifications corresponding to this change
  623. */
  624. public function GetDescription()
  625. {
  626. return $this->Get('description');
  627. }
  628. }
  629. /**
  630. * Record added/removed objects from within a link set
  631. *
  632. * @package iTopORM
  633. */
  634. abstract class CMDBChangeOpSetAttributeLinks extends CMDBChangeOpSetAttribute
  635. {
  636. public static function Init()
  637. {
  638. $aParams = array
  639. (
  640. "category" => "core/cmdb",
  641. "key_type" => "",
  642. "name_attcode" => "change",
  643. "state_attcode" => "",
  644. "reconc_keys" => array(),
  645. "db_table" => "priv_changeop_links",
  646. "db_key_field" => "id",
  647. "db_finalclass_field" => "",
  648. );
  649. MetaModel::Init_Params($aParams);
  650. MetaModel::Init_InheritAttributes();
  651. // Note: item class/id points to the link class itself in case of a direct link set (e.g. Server::interface_list => Interface)
  652. // item class/id points to the remote class in case of a indirect link set (e.g. Server::contract_list => Contract)
  653. MetaModel::Init_AddAttribute(new AttributeString("item_class", array("allowed_values"=>null, "sql"=>"item_class", "default_value"=>'', "is_null_allowed"=>false, "depends_on"=>array())));
  654. MetaModel::Init_AddAttribute(new AttributeInteger("item_id", array("allowed_values"=>null, "sql"=>"item_id", "default_value"=>0, "is_null_allowed"=>false, "depends_on"=>array())));
  655. }
  656. }
  657. /**
  658. * Record added/removed objects from within a link set
  659. *
  660. * @package iTopORM
  661. */
  662. class CMDBChangeOpSetAttributeLinksAddRemove extends CMDBChangeOpSetAttributeLinks
  663. {
  664. public static function Init()
  665. {
  666. $aParams = array
  667. (
  668. "category" => "core/cmdb",
  669. "key_type" => "",
  670. "name_attcode" => "change",
  671. "state_attcode" => "",
  672. "reconc_keys" => array(),
  673. "db_table" => "priv_changeop_links_addremove",
  674. "db_key_field" => "id",
  675. "db_finalclass_field" => "",
  676. );
  677. MetaModel::Init_Params($aParams);
  678. MetaModel::Init_InheritAttributes();
  679. MetaModel::Init_AddAttribute(new AttributeEnum("type", array("allowed_values"=>new ValueSetEnum('added,removed'), "sql"=>"type", "default_value"=>"added", "is_null_allowed"=>false, "depends_on"=>array())));
  680. }
  681. /**
  682. * Describe (as a text string) the modifications corresponding to this change
  683. */
  684. public function GetDescription()
  685. {
  686. $sResult = '';
  687. $oTargetObjectClass = $this->Get('objclass');
  688. $oTargetObjectKey = $this->Get('objkey');
  689. $oTargetSearch = new DBObjectSearch($oTargetObjectClass);
  690. $oTargetSearch->AddCondition('id', $oTargetObjectKey, '=');
  691. $oMonoObjectSet = new DBObjectSet($oTargetSearch);
  692. if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES)
  693. {
  694. if (!MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) return ''; // Protects against renamed attributes...
  695. $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode'));
  696. $sAttName = $oAttDef->GetLabel();
  697. $sItemDesc = MetaModel::GetHyperLink($this->Get('item_class'), $this->Get('item_id'));
  698. $sResult = $sAttName.' - ';
  699. switch ($this->Get('type'))
  700. {
  701. case 'added':
  702. $sResult .= Dict::Format('Change:LinkSet:Added', $sItemDesc);
  703. break;
  704. case 'removed':
  705. $sResult .= Dict::Format('Change:LinkSet:Removed', $sItemDesc);
  706. break;
  707. }
  708. }
  709. return $sResult;
  710. }
  711. }
  712. /**
  713. * Record attribute changes from within a link set
  714. * A single record redirects to the modifications made within the same change
  715. *
  716. * @package iTopORM
  717. */
  718. class CMDBChangeOpSetAttributeLinksTune extends CMDBChangeOpSetAttributeLinks
  719. {
  720. public static function Init()
  721. {
  722. $aParams = array
  723. (
  724. "category" => "core/cmdb",
  725. "key_type" => "",
  726. "name_attcode" => "change",
  727. "state_attcode" => "",
  728. "reconc_keys" => array(),
  729. "db_table" => "priv_changeop_links_tune",
  730. "db_key_field" => "id",
  731. "db_finalclass_field" => "",
  732. );
  733. MetaModel::Init_Params($aParams);
  734. MetaModel::Init_InheritAttributes();
  735. MetaModel::Init_AddAttribute(new AttributeInteger("link_id", array("allowed_values"=>null, "sql"=>"link_id", "default_value"=>0, "is_null_allowed"=>false, "depends_on"=>array())));
  736. }
  737. /**
  738. * Describe (as a text string) the modifications corresponding to this change
  739. */
  740. public function GetDescription()
  741. {
  742. $sResult = '';
  743. $oTargetObjectClass = $this->Get('objclass');
  744. $oTargetObjectKey = $this->Get('objkey');
  745. $oTargetSearch = new DBObjectSearch($oTargetObjectClass);
  746. $oTargetSearch->AddCondition('id', $oTargetObjectKey, '=');
  747. $oMonoObjectSet = new DBObjectSet($oTargetSearch);
  748. if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES)
  749. {
  750. if (!MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) return ''; // Protects against renamed attributes...
  751. $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode'));
  752. $sAttName = $oAttDef->GetLabel();
  753. $sLinkClass = $oAttDef->GetLinkedClass();
  754. $aLinkClasses = MetaModel::EnumChildClasses($sLinkClass, ENUM_CHILD_CLASSES_ALL);
  755. // Search for changes on the corresponding link
  756. //
  757. $oSearch = new DBObjectSearch('CMDBChangeOpSetAttribute');
  758. $oSearch->AddCondition('change', $this->Get('change'), '=');
  759. $oSearch->AddCondition('objkey', $this->Get('link_id'), '=');
  760. if (count($aLinkClasses) == 1)
  761. {
  762. // Faster than the whole building of the expression below for just one value ??
  763. $oSearch->AddCondition('objclass', $sLinkClass, '=');
  764. }
  765. else
  766. {
  767. $oField = new FieldExpression('objclass', $oSearch->GetClassAlias());
  768. $sListExpr = '('.implode(', ', CMDBSource::Quote($aLinkClasses)).')';
  769. $sOQLCondition = $oField->Render()." IN $sListExpr";
  770. $oNewCondition = Expression::FromOQL($sOQLCondition);
  771. $oSearch->AddConditionExpression($oNewCondition);
  772. }
  773. $oSet = new DBObjectSet($oSearch);
  774. $aChanges = array();
  775. while ($oChangeOp = $oSet->Fetch())
  776. {
  777. $aChanges[] = $oChangeOp->GetDescription();
  778. }
  779. if (count($aChanges) == 0)
  780. {
  781. return '';
  782. }
  783. $sItemDesc = MetaModel::GetHyperLink($this->Get('item_class'), $this->Get('item_id'));
  784. $sResult = $sAttName.' - ';
  785. $sResult .= Dict::Format('Change:LinkSet:Modified', $sItemDesc);
  786. $sResult .= ' : '.implode(', ', $aChanges);
  787. }
  788. return $sResult;
  789. }
  790. }
  791. ?>