cmdbchangeop.class.inc.php 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913
  1. <?php
  2. // Copyright (C) 2010-2016 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-2016 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. $sResult = '';
  487. $oTargetObjectClass = $this->Get('objclass');
  488. $oTargetObjectKey = $this->Get('objkey');
  489. $oTargetSearch = new DBObjectSearch($oTargetObjectClass);
  490. $oTargetSearch->AddCondition('id', $oTargetObjectKey, '=');
  491. $oMonoObjectSet = new DBObjectSet($oTargetSearch);
  492. if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES)
  493. {
  494. if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode')))
  495. {
  496. $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode'));
  497. $sAttName = $oAttDef->GetLabel();
  498. }
  499. else
  500. {
  501. // The attribute was renamed or removed from the object ?
  502. $sAttName = $this->Get('attcode');
  503. }
  504. $sTextView = '<div>'.$this->GetAsHtml('prevdata').'</div>';
  505. //$sDocView = $oPrevDoc->GetDisplayInline(get_class($this), $this->GetKey(), 'prevdata');
  506. $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sTextView);
  507. }
  508. return $sResult;
  509. }
  510. }
  511. /**
  512. * Record the modification of a multiline string (text) containing some HTML markup
  513. *
  514. * @package iTopORM
  515. */
  516. class CMDBChangeOpSetAttributeHTML extends CMDBChangeOpSetAttributeLongText
  517. {
  518. public static function Init()
  519. {
  520. $aParams = array
  521. (
  522. "category" => "core/cmdb",
  523. "key_type" => "",
  524. "name_attcode" => "change",
  525. "state_attcode" => "",
  526. "reconc_keys" => array(),
  527. "db_table" => "priv_changeop_setatt_html",
  528. "db_key_field" => "id",
  529. "db_finalclass_field" => "",
  530. );
  531. MetaModel::Init_Params($aParams);
  532. MetaModel::Init_InheritAttributes();
  533. // Display lists
  534. MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details
  535. MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list
  536. }
  537. /**
  538. * Describe (as a text string) the modifications corresponding to this change
  539. */
  540. public function GetDescription()
  541. {
  542. $sResult = '';
  543. $oTargetObjectClass = $this->Get('objclass');
  544. $oTargetObjectKey = $this->Get('objkey');
  545. $oTargetSearch = new DBObjectSearch($oTargetObjectClass);
  546. $oTargetSearch->AddCondition('id', $oTargetObjectKey, '=');
  547. $oMonoObjectSet = new DBObjectSet($oTargetSearch);
  548. if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES)
  549. {
  550. if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode')))
  551. {
  552. $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode'));
  553. $sAttName = $oAttDef->GetLabel();
  554. }
  555. else
  556. {
  557. // The attribute was renamed or removed from the object ?
  558. $sAttName = $this->Get('attcode');
  559. }
  560. $sTextView = '<div class="history_entry history_entry_truncated"><div class="history_html_content">'.$this->Get('prevdata').'</div></div>';
  561. //$sDocView = $oPrevDoc->GetDisplayInline(get_class($this), $this->GetKey(), 'prevdata');
  562. $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sTextView);
  563. }
  564. return $sResult;
  565. }
  566. }
  567. /**
  568. * Record the modification of a caselog (text)
  569. * since the caselog itself stores the history
  570. * of its entries, there is no need to duplicate
  571. * the text here
  572. *
  573. * @package iTopORM
  574. */
  575. class CMDBChangeOpSetAttributeCaseLog extends CMDBChangeOpSetAttribute
  576. {
  577. public static function Init()
  578. {
  579. $aParams = array
  580. (
  581. "category" => "core/cmdb",
  582. "key_type" => "",
  583. "name_attcode" => "change",
  584. "state_attcode" => "",
  585. "reconc_keys" => array(),
  586. "db_table" => "priv_changeop_setatt_log",
  587. "db_key_field" => "id",
  588. "db_finalclass_field" => "",
  589. );
  590. MetaModel::Init_Params($aParams);
  591. MetaModel::Init_InheritAttributes();
  592. MetaModel::Init_AddAttribute(new AttributeInteger("lastentry", array("allowed_values"=>null, "sql"=>"lastentry", "default_value"=>0, "is_null_allowed"=>true, "depends_on"=>array())));
  593. // Display lists
  594. MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details
  595. MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list
  596. }
  597. /**
  598. * Describe (as a text string) the modifications corresponding to this change
  599. */
  600. public function GetDescription()
  601. {
  602. // Temporary, until we change the options of GetDescription() -needs a more global revision
  603. $bIsHtml = true;
  604. $sResult = '';
  605. $oTargetObjectClass = $this->Get('objclass');
  606. $oTargetObjectKey = $this->Get('objkey');
  607. $oTargetSearch = new DBObjectSearch($oTargetObjectClass);
  608. $oTargetSearch->AddCondition('id', $oTargetObjectKey, '=');
  609. $oMonoObjectSet = new DBObjectSet($oTargetSearch);
  610. if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES)
  611. {
  612. if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode')))
  613. {
  614. $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode'));
  615. $sAttName = $oAttDef->GetLabel();
  616. }
  617. else
  618. {
  619. // The attribute was renamed or removed from the object ?
  620. $sAttName = $this->Get('attcode');
  621. }
  622. $oObj = $oMonoObjectSet->Fetch();
  623. $oCaseLog = $oObj->Get($this->Get('attcode'));
  624. $iMaxVisibleLength = MetaModel::getConfig()->Get('max_history_case_log_entry_length', 0);
  625. $sTextEntry = '<div class="history_entry history_entry_truncated"><div class="history_html_content">'.$oCaseLog->GetEntryAt($this->Get('lastentry')).'</div></div>';
  626. $sResult = Dict::Format('Change:AttName_EntryAdded', $sAttName, $sTextEntry);
  627. }
  628. return $sResult;
  629. }
  630. protected function ToHtml($sRawText)
  631. {
  632. return str_replace(array("\r\n", "\n", "\r"), "<br/>", htmlentities($sRawText, ENT_QUOTES, 'UTF-8'));
  633. }
  634. }
  635. /**
  636. * Record an action made by a plug-in
  637. *
  638. * @package iTopORM
  639. */
  640. class CMDBChangeOpPlugin extends CMDBChangeOp
  641. {
  642. public static function Init()
  643. {
  644. $aParams = array
  645. (
  646. "category" => "core/cmdb",
  647. "key_type" => "",
  648. "name_attcode" => "change",
  649. "state_attcode" => "",
  650. "reconc_keys" => array(),
  651. "db_table" => "priv_changeop_plugin",
  652. "db_key_field" => "id",
  653. "db_finalclass_field" => "",
  654. );
  655. MetaModel::Init_Params($aParams);
  656. MetaModel::Init_AddAttribute(new AttributeString("description", array("allowed_values"=>null, "sql"=>"description", "default_value"=>'', "is_null_allowed"=>false, "depends_on"=>array())));
  657. /* 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
  658. MetaModel::Init_AddAttribute(new AttributeString("extension_class", array("allowed_values"=>null, "sql"=>"extension_class", "default_value"=>'', "is_null_allowed"=>false, "depends_on"=>array())));
  659. MetaModel::Init_AddAttribute(new AttributeInteger("extension_id", array("allowed_values"=>null, "sql"=>"extension_id", "default_value"=>0, "is_null_allowed"=>false, "depends_on"=>array())));
  660. */
  661. MetaModel::Init_InheritAttributes();
  662. }
  663. /**
  664. * Describe (as a text string) the modifications corresponding to this change
  665. */
  666. public function GetDescription()
  667. {
  668. return $this->Get('description');
  669. }
  670. }
  671. /**
  672. * Record added/removed objects from within a link set
  673. *
  674. * @package iTopORM
  675. */
  676. abstract class CMDBChangeOpSetAttributeLinks extends CMDBChangeOpSetAttribute
  677. {
  678. public static function Init()
  679. {
  680. $aParams = array
  681. (
  682. "category" => "core/cmdb",
  683. "key_type" => "",
  684. "name_attcode" => "change",
  685. "state_attcode" => "",
  686. "reconc_keys" => array(),
  687. "db_table" => "priv_changeop_links",
  688. "db_key_field" => "id",
  689. "db_finalclass_field" => "",
  690. );
  691. MetaModel::Init_Params($aParams);
  692. MetaModel::Init_InheritAttributes();
  693. // Note: item class/id points to the link class itself in case of a direct link set (e.g. Server::interface_list => Interface)
  694. // item class/id points to the remote class in case of a indirect link set (e.g. Server::contract_list => Contract)
  695. MetaModel::Init_AddAttribute(new AttributeString("item_class", array("allowed_values"=>null, "sql"=>"item_class", "default_value"=>'', "is_null_allowed"=>false, "depends_on"=>array())));
  696. MetaModel::Init_AddAttribute(new AttributeInteger("item_id", array("allowed_values"=>null, "sql"=>"item_id", "default_value"=>0, "is_null_allowed"=>false, "depends_on"=>array())));
  697. }
  698. }
  699. /**
  700. * Record added/removed objects from within a link set
  701. *
  702. * @package iTopORM
  703. */
  704. class CMDBChangeOpSetAttributeLinksAddRemove extends CMDBChangeOpSetAttributeLinks
  705. {
  706. public static function Init()
  707. {
  708. $aParams = array
  709. (
  710. "category" => "core/cmdb",
  711. "key_type" => "",
  712. "name_attcode" => "change",
  713. "state_attcode" => "",
  714. "reconc_keys" => array(),
  715. "db_table" => "priv_changeop_links_addremove",
  716. "db_key_field" => "id",
  717. "db_finalclass_field" => "",
  718. );
  719. MetaModel::Init_Params($aParams);
  720. MetaModel::Init_InheritAttributes();
  721. 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())));
  722. }
  723. /**
  724. * Describe (as a text string) the modifications corresponding to this change
  725. */
  726. public function GetDescription()
  727. {
  728. $sResult = '';
  729. $oTargetObjectClass = $this->Get('objclass');
  730. $oTargetObjectKey = $this->Get('objkey');
  731. $oTargetSearch = new DBObjectSearch($oTargetObjectClass);
  732. $oTargetSearch->AddCondition('id', $oTargetObjectKey, '=');
  733. $oMonoObjectSet = new DBObjectSet($oTargetSearch);
  734. if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES)
  735. {
  736. if (!MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) return ''; // Protects against renamed attributes...
  737. $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode'));
  738. $sAttName = $oAttDef->GetLabel();
  739. $sItemDesc = MetaModel::GetHyperLink($this->Get('item_class'), $this->Get('item_id'));
  740. $sResult = $sAttName.' - ';
  741. switch ($this->Get('type'))
  742. {
  743. case 'added':
  744. $sResult .= Dict::Format('Change:LinkSet:Added', $sItemDesc);
  745. break;
  746. case 'removed':
  747. $sResult .= Dict::Format('Change:LinkSet:Removed', $sItemDesc);
  748. break;
  749. }
  750. }
  751. return $sResult;
  752. }
  753. }
  754. /**
  755. * Record attribute changes from within a link set
  756. * A single record redirects to the modifications made within the same change
  757. *
  758. * @package iTopORM
  759. */
  760. class CMDBChangeOpSetAttributeLinksTune extends CMDBChangeOpSetAttributeLinks
  761. {
  762. public static function Init()
  763. {
  764. $aParams = array
  765. (
  766. "category" => "core/cmdb",
  767. "key_type" => "",
  768. "name_attcode" => "change",
  769. "state_attcode" => "",
  770. "reconc_keys" => array(),
  771. "db_table" => "priv_changeop_links_tune",
  772. "db_key_field" => "id",
  773. "db_finalclass_field" => "",
  774. );
  775. MetaModel::Init_Params($aParams);
  776. MetaModel::Init_InheritAttributes();
  777. MetaModel::Init_AddAttribute(new AttributeInteger("link_id", array("allowed_values"=>null, "sql"=>"link_id", "default_value"=>0, "is_null_allowed"=>false, "depends_on"=>array())));
  778. }
  779. /**
  780. * Describe (as a text string) the modifications corresponding to this change
  781. */
  782. public function GetDescription()
  783. {
  784. $sResult = '';
  785. $oTargetObjectClass = $this->Get('objclass');
  786. $oTargetObjectKey = $this->Get('objkey');
  787. $oTargetSearch = new DBObjectSearch($oTargetObjectClass);
  788. $oTargetSearch->AddCondition('id', $oTargetObjectKey, '=');
  789. $oMonoObjectSet = new DBObjectSet($oTargetSearch);
  790. if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES)
  791. {
  792. if (!MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) return ''; // Protects against renamed attributes...
  793. $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode'));
  794. $sAttName = $oAttDef->GetLabel();
  795. $sLinkClass = $oAttDef->GetLinkedClass();
  796. $aLinkClasses = MetaModel::EnumChildClasses($sLinkClass, ENUM_CHILD_CLASSES_ALL);
  797. // Search for changes on the corresponding link
  798. //
  799. $oSearch = new DBObjectSearch('CMDBChangeOpSetAttribute');
  800. $oSearch->AddCondition('change', $this->Get('change'), '=');
  801. $oSearch->AddCondition('objkey', $this->Get('link_id'), '=');
  802. if (count($aLinkClasses) == 1)
  803. {
  804. // Faster than the whole building of the expression below for just one value ??
  805. $oSearch->AddCondition('objclass', $sLinkClass, '=');
  806. }
  807. else
  808. {
  809. $oField = new FieldExpression('objclass', $oSearch->GetClassAlias());
  810. $sListExpr = '('.implode(', ', CMDBSource::Quote($aLinkClasses)).')';
  811. $sOQLCondition = $oField->Render()." IN $sListExpr";
  812. $oNewCondition = Expression::FromOQL($sOQLCondition);
  813. $oSearch->AddConditionExpression($oNewCondition);
  814. }
  815. $oSet = new DBObjectSet($oSearch);
  816. $aChanges = array();
  817. while ($oChangeOp = $oSet->Fetch())
  818. {
  819. $aChanges[] = $oChangeOp->GetDescription();
  820. }
  821. if (count($aChanges) == 0)
  822. {
  823. return '';
  824. }
  825. $sItemDesc = MetaModel::GetHyperLink($this->Get('item_class'), $this->Get('item_id'));
  826. $sResult = $sAttName.' - ';
  827. $sResult .= Dict::Format('Change:LinkSet:Modified', $sItemDesc);
  828. $sResult .= ' : '.implode(', ', $aChanges);
  829. }
  830. return $sResult;
  831. }
  832. }
  833. ?>