cmdbchangeop.class.inc.php 37 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042
  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 an URL
  224. *
  225. * @package iTopORM
  226. */
  227. class CMDBChangeOpSetAttributeURL 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_url",
  239. "db_key_field" => "id",
  240. "db_finalclass_field" => "",
  241. );
  242. MetaModel::Init_Params($aParams);
  243. MetaModel::Init_InheritAttributes();
  244. MetaModel::Init_AddAttribute(new AttributeURL("oldvalue", array("allowed_values"=>null, "sql"=>"oldvalue", "target" => '_blank', "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array())));
  245. MetaModel::Init_AddAttribute(new AttributeURL("newvalue", array("allowed_values"=>null, "sql"=>"newvalue", "target" => '_blank', "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array())));
  246. // Display lists
  247. MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode', 'oldvalue', 'newvalue')); // Attributes to be displayed for the complete details
  248. MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode', 'oldvalue', 'newvalue')); // Attributes to be displayed for a list
  249. }
  250. /**
  251. * Describe (as a text string) the modifications corresponding to this change
  252. */
  253. public function GetDescription()
  254. {
  255. $sResult = '';
  256. $oTargetObjectClass = $this->Get('objclass');
  257. $oTargetObjectKey = $this->Get('objkey');
  258. $oTargetSearch = new DBObjectSearch($oTargetObjectClass);
  259. $oTargetSearch->AddCondition('id', $oTargetObjectKey, '=');
  260. $oMonoObjectSet = new DBObjectSet($oTargetSearch);
  261. if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES)
  262. {
  263. if (!MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) return ''; // Protects against renamed attributes...
  264. $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode'));
  265. $sAttName = $oAttDef->GetLabel();
  266. $sNewValue = $this->Get('newvalue');
  267. $sOldValue = $this->Get('oldvalue');
  268. $sResult = $oAttDef->DescribeChangeAsHTML($sOldValue, $sNewValue);
  269. }
  270. return $sResult;
  271. }
  272. }
  273. /**
  274. * Record the modification of a blob
  275. *
  276. * @package iTopORM
  277. */
  278. class CMDBChangeOpSetAttributeBlob extends CMDBChangeOpSetAttribute
  279. {
  280. public static function Init()
  281. {
  282. $aParams = array
  283. (
  284. "category" => "core/cmdb",
  285. "key_type" => "",
  286. "name_attcode" => "change",
  287. "state_attcode" => "",
  288. "reconc_keys" => array(),
  289. "db_table" => "priv_changeop_setatt_data",
  290. "db_key_field" => "id",
  291. "db_finalclass_field" => "",
  292. );
  293. MetaModel::Init_Params($aParams);
  294. MetaModel::Init_InheritAttributes();
  295. MetaModel::Init_AddAttribute(new AttributeBlob("prevdata", array("depends_on"=>array())));
  296. // Display lists
  297. MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details
  298. MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list
  299. }
  300. /**
  301. * Describe (as a text string) the modifications corresponding to this change
  302. */
  303. public function GetDescription()
  304. {
  305. // Temporary, until we change the options of GetDescription() -needs a more global revision
  306. $bIsHtml = true;
  307. $sResult = '';
  308. $oTargetObjectClass = $this->Get('objclass');
  309. $oTargetObjectKey = $this->Get('objkey');
  310. $oTargetSearch = new DBObjectSearch($oTargetObjectClass);
  311. $oTargetSearch->AddCondition('id', $oTargetObjectKey, '=');
  312. $oMonoObjectSet = new DBObjectSet($oTargetSearch);
  313. if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES)
  314. {
  315. if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode')))
  316. {
  317. $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode'));
  318. $sAttName = $oAttDef->GetLabel();
  319. }
  320. else
  321. {
  322. // The attribute was renamed or removed from the object ?
  323. $sAttName = $this->Get('attcode');
  324. }
  325. $oPrevDoc = $this->Get('prevdata');
  326. if ($oPrevDoc->IsEmpty())
  327. {
  328. $sPrevious = '';
  329. $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sPrevious);
  330. }
  331. else
  332. {
  333. $sDocView = $oPrevDoc->GetAsHtml();
  334. $sDocView .= "<br/>".Dict::Format('UI:OpenDocumentInNewWindow_', $oPrevDoc->GetDisplayLink(get_class($this), $this->GetKey(), 'prevdata')).", \n";
  335. $sDocView .= Dict::Format('UI:DownloadDocument_', $oPrevDoc->GetDownloadLink(get_class($this), $this->GetKey(), 'prevdata'))."\n";
  336. //$sDocView = $oPrevDoc->GetDisplayInline(get_class($this), $this->GetKey(), 'prevdata');
  337. $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sDocView);
  338. }
  339. }
  340. return $sResult;
  341. }
  342. }
  343. /**
  344. * Safely record the modification of one way encrypted password
  345. */
  346. class CMDBChangeOpSetAttributeOneWayPassword extends CMDBChangeOpSetAttribute
  347. {
  348. public static function Init()
  349. {
  350. $aParams = array
  351. (
  352. "category" => "core/cmdb",
  353. "key_type" => "",
  354. "name_attcode" => "change",
  355. "state_attcode" => "",
  356. "reconc_keys" => array(),
  357. "db_table" => "priv_changeop_setatt_pwd",
  358. "db_key_field" => "id",
  359. "db_finalclass_field" => "",
  360. );
  361. MetaModel::Init_Params($aParams);
  362. MetaModel::Init_InheritAttributes();
  363. MetaModel::Init_AddAttribute(new AttributeOneWayPassword("prev_pwd", array("sql" => 'data', "default_value" => '', "is_null_allowed"=> true, "allowed_values" => null, "depends_on"=>array())));
  364. // Display lists
  365. MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details
  366. MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list
  367. }
  368. /**
  369. * Describe (as a text string) the modifications corresponding to this change
  370. */
  371. public function GetDescription()
  372. {
  373. // Temporary, until we change the options of GetDescription() -needs a more global revision
  374. $bIsHtml = true;
  375. $sResult = '';
  376. $oTargetObjectClass = $this->Get('objclass');
  377. $oTargetObjectKey = $this->Get('objkey');
  378. $oTargetSearch = new DBObjectSearch($oTargetObjectClass);
  379. $oTargetSearch->AddCondition('id', $oTargetObjectKey, '=');
  380. $oMonoObjectSet = new DBObjectSet($oTargetSearch);
  381. if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES)
  382. {
  383. if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode')))
  384. {
  385. $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode'));
  386. $sAttName = $oAttDef->GetLabel();
  387. }
  388. else
  389. {
  390. // The attribute was renamed or removed from the object ?
  391. $sAttName = $this->Get('attcode');
  392. }
  393. $sResult = Dict::Format('Change:AttName_Changed', $sAttName);
  394. }
  395. return $sResult;
  396. }
  397. }
  398. /**
  399. * Safely record the modification of an encrypted field
  400. */
  401. class CMDBChangeOpSetAttributeEncrypted extends CMDBChangeOpSetAttribute
  402. {
  403. public static function Init()
  404. {
  405. $aParams = array
  406. (
  407. "category" => "core/cmdb",
  408. "key_type" => "",
  409. "name_attcode" => "change",
  410. "state_attcode" => "",
  411. "reconc_keys" => array(),
  412. "db_table" => "priv_changeop_setatt_encrypted",
  413. "db_key_field" => "id",
  414. "db_finalclass_field" => "",
  415. );
  416. MetaModel::Init_Params($aParams);
  417. MetaModel::Init_InheritAttributes();
  418. MetaModel::Init_AddAttribute(new AttributeEncryptedString("prevstring", array("sql" => 'data', "default_value" => '', "is_null_allowed"=> true, "allowed_values" => null, "depends_on"=>array())));
  419. // Display lists
  420. MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details
  421. MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list
  422. }
  423. /**
  424. * Describe (as a text string) the modifications corresponding to this change
  425. */
  426. public function GetDescription()
  427. {
  428. // Temporary, until we change the options of GetDescription() -needs a more global revision
  429. $bIsHtml = true;
  430. $sResult = '';
  431. $oTargetObjectClass = $this->Get('objclass');
  432. $oTargetObjectKey = $this->Get('objkey');
  433. $oTargetSearch = new DBObjectSearch($oTargetObjectClass);
  434. $oTargetSearch->AddCondition('id', $oTargetObjectKey, '=');
  435. $oMonoObjectSet = new DBObjectSet($oTargetSearch);
  436. if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES)
  437. {
  438. if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode')))
  439. {
  440. $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode'));
  441. $sAttName = $oAttDef->GetLabel();
  442. }
  443. else
  444. {
  445. // The attribute was renamed or removed from the object ?
  446. $sAttName = $this->Get('attcode');
  447. }
  448. $sPrevString = $this->Get('prevstring');
  449. $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sPrevString);
  450. }
  451. return $sResult;
  452. }
  453. }
  454. /**
  455. * Record the modification of a multiline string (text)
  456. *
  457. * @package iTopORM
  458. */
  459. class CMDBChangeOpSetAttributeText 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_text",
  471. "db_key_field" => "id",
  472. "db_finalclass_field" => "",
  473. );
  474. MetaModel::Init_Params($aParams);
  475. MetaModel::Init_InheritAttributes();
  476. MetaModel::Init_AddAttribute(new AttributeText("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 multiline string (text)
  515. *
  516. * @package iTopORM
  517. */
  518. class CMDBChangeOpSetAttributeLongText extends CMDBChangeOpSetAttribute
  519. {
  520. public static function Init()
  521. {
  522. $aParams = array
  523. (
  524. "category" => "core/cmdb",
  525. "key_type" => "",
  526. "name_attcode" => "change",
  527. "state_attcode" => "",
  528. "reconc_keys" => array(),
  529. "db_table" => "priv_changeop_setatt_longtext",
  530. "db_key_field" => "id",
  531. "db_finalclass_field" => "",
  532. );
  533. MetaModel::Init_Params($aParams);
  534. MetaModel::Init_InheritAttributes();
  535. MetaModel::Init_AddAttribute(new AttributeLongText("prevdata", array("allowed_values"=>null, "sql"=>"prevdata", "default_value"=>"", "is_null_allowed"=>true, "depends_on"=>array())));
  536. // Display lists
  537. MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details
  538. MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list
  539. }
  540. /**
  541. * Describe (as a text string) the modifications corresponding to this change
  542. */
  543. public function GetDescription()
  544. {
  545. $sResult = '';
  546. $oTargetObjectClass = $this->Get('objclass');
  547. $oTargetObjectKey = $this->Get('objkey');
  548. $oTargetSearch = new DBObjectSearch($oTargetObjectClass);
  549. $oTargetSearch->AddCondition('id', $oTargetObjectKey, '=');
  550. $oMonoObjectSet = new DBObjectSet($oTargetSearch);
  551. if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES)
  552. {
  553. if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode')))
  554. {
  555. $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode'));
  556. $sAttName = $oAttDef->GetLabel();
  557. }
  558. else
  559. {
  560. // The attribute was renamed or removed from the object ?
  561. $sAttName = $this->Get('attcode');
  562. }
  563. $sTextView = '<div>'.$this->GetAsHtml('prevdata').'</div>';
  564. //$sDocView = $oPrevDoc->GetDisplayInline(get_class($this), $this->GetKey(), 'prevdata');
  565. $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sTextView);
  566. }
  567. return $sResult;
  568. }
  569. }
  570. /**
  571. * Record the modification of a multiline string (text) containing some HTML markup
  572. *
  573. * @package iTopORM
  574. */
  575. class CMDBChangeOpSetAttributeHTML extends CMDBChangeOpSetAttributeLongText
  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_html",
  587. "db_key_field" => "id",
  588. "db_finalclass_field" => "",
  589. );
  590. MetaModel::Init_Params($aParams);
  591. MetaModel::Init_InheritAttributes();
  592. // Display lists
  593. MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details
  594. MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list
  595. }
  596. /**
  597. * Describe (as a text string) the modifications corresponding to this change
  598. */
  599. public function GetDescription()
  600. {
  601. $sResult = '';
  602. $oTargetObjectClass = $this->Get('objclass');
  603. $oTargetObjectKey = $this->Get('objkey');
  604. $oTargetSearch = new DBObjectSearch($oTargetObjectClass);
  605. $oTargetSearch->AddCondition('id', $oTargetObjectKey, '=');
  606. $oMonoObjectSet = new DBObjectSet($oTargetSearch);
  607. if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES)
  608. {
  609. if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode')))
  610. {
  611. $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode'));
  612. $sAttName = $oAttDef->GetLabel();
  613. }
  614. else
  615. {
  616. // The attribute was renamed or removed from the object ?
  617. $sAttName = $this->Get('attcode');
  618. }
  619. $sTextView = '<div class="history_entry history_entry_truncated"><div class="history_html_content">'.$this->Get('prevdata').'</div></div>';
  620. //$sDocView = $oPrevDoc->GetDisplayInline(get_class($this), $this->GetKey(), 'prevdata');
  621. $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sTextView);
  622. }
  623. return $sResult;
  624. }
  625. }
  626. /**
  627. * Record the modification of a caselog (text)
  628. * since the caselog itself stores the history
  629. * of its entries, there is no need to duplicate
  630. * the text here
  631. *
  632. * @package iTopORM
  633. */
  634. class CMDBChangeOpSetAttributeCaseLog 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_setatt_log",
  646. "db_key_field" => "id",
  647. "db_finalclass_field" => "",
  648. );
  649. MetaModel::Init_Params($aParams);
  650. MetaModel::Init_InheritAttributes();
  651. MetaModel::Init_AddAttribute(new AttributeInteger("lastentry", array("allowed_values"=>null, "sql"=>"lastentry", "default_value"=>0, "is_null_allowed"=>true, "depends_on"=>array())));
  652. // Display lists
  653. MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details
  654. MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list
  655. }
  656. /**
  657. * Describe (as a text string) the modifications corresponding to this change
  658. */
  659. public function GetDescription()
  660. {
  661. // Temporary, until we change the options of GetDescription() -needs a more global revision
  662. $bIsHtml = true;
  663. $sResult = '';
  664. $oTargetObjectClass = $this->Get('objclass');
  665. $oTargetObjectKey = $this->Get('objkey');
  666. $oTargetSearch = new DBObjectSearch($oTargetObjectClass);
  667. $oTargetSearch->AddCondition('id', $oTargetObjectKey, '=');
  668. $oMonoObjectSet = new DBObjectSet($oTargetSearch);
  669. if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES)
  670. {
  671. if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode')))
  672. {
  673. $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode'));
  674. $sAttName = $oAttDef->GetLabel();
  675. }
  676. else
  677. {
  678. // The attribute was renamed or removed from the object ?
  679. $sAttName = $this->Get('attcode');
  680. }
  681. $oObj = $oMonoObjectSet->Fetch();
  682. $oCaseLog = $oObj->Get($this->Get('attcode'));
  683. $iMaxVisibleLength = MetaModel::getConfig()->Get('max_history_case_log_entry_length', 0);
  684. $sTextEntry = '<div class="history_entry history_entry_truncated"><div class="history_html_content">'.$oCaseLog->GetEntryAt($this->Get('lastentry')).'</div></div>';
  685. $sResult = Dict::Format('Change:AttName_EntryAdded', $sAttName, $sTextEntry);
  686. }
  687. return $sResult;
  688. }
  689. protected function ToHtml($sRawText)
  690. {
  691. return str_replace(array("\r\n", "\n", "\r"), "<br/>", htmlentities($sRawText, ENT_QUOTES, 'UTF-8'));
  692. }
  693. }
  694. /**
  695. * Record an action made by a plug-in
  696. *
  697. * @package iTopORM
  698. */
  699. class CMDBChangeOpPlugin extends CMDBChangeOp
  700. {
  701. public static function Init()
  702. {
  703. $aParams = array
  704. (
  705. "category" => "core/cmdb",
  706. "key_type" => "",
  707. "name_attcode" => "change",
  708. "state_attcode" => "",
  709. "reconc_keys" => array(),
  710. "db_table" => "priv_changeop_plugin",
  711. "db_key_field" => "id",
  712. "db_finalclass_field" => "",
  713. );
  714. MetaModel::Init_Params($aParams);
  715. MetaModel::Init_AddAttribute(new AttributeString("description", array("allowed_values"=>null, "sql"=>"description", "default_value"=>'', "is_null_allowed"=>false, "depends_on"=>array())));
  716. /* 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
  717. MetaModel::Init_AddAttribute(new AttributeString("extension_class", array("allowed_values"=>null, "sql"=>"extension_class", "default_value"=>'', "is_null_allowed"=>false, "depends_on"=>array())));
  718. MetaModel::Init_AddAttribute(new AttributeInteger("extension_id", array("allowed_values"=>null, "sql"=>"extension_id", "default_value"=>0, "is_null_allowed"=>false, "depends_on"=>array())));
  719. */
  720. MetaModel::Init_InheritAttributes();
  721. }
  722. /**
  723. * Describe (as a text string) the modifications corresponding to this change
  724. */
  725. public function GetDescription()
  726. {
  727. return $this->Get('description');
  728. }
  729. }
  730. /**
  731. * Record added/removed objects from within a link set
  732. *
  733. * @package iTopORM
  734. */
  735. abstract class CMDBChangeOpSetAttributeLinks extends CMDBChangeOpSetAttribute
  736. {
  737. public static function Init()
  738. {
  739. $aParams = array
  740. (
  741. "category" => "core/cmdb",
  742. "key_type" => "",
  743. "name_attcode" => "change",
  744. "state_attcode" => "",
  745. "reconc_keys" => array(),
  746. "db_table" => "priv_changeop_links",
  747. "db_key_field" => "id",
  748. "db_finalclass_field" => "",
  749. );
  750. MetaModel::Init_Params($aParams);
  751. MetaModel::Init_InheritAttributes();
  752. // Note: item class/id points to the link class itself in case of a direct link set (e.g. Server::interface_list => Interface)
  753. // item class/id points to the remote class in case of a indirect link set (e.g. Server::contract_list => Contract)
  754. MetaModel::Init_AddAttribute(new AttributeString("item_class", array("allowed_values"=>null, "sql"=>"item_class", "default_value"=>'', "is_null_allowed"=>false, "depends_on"=>array())));
  755. MetaModel::Init_AddAttribute(new AttributeInteger("item_id", array("allowed_values"=>null, "sql"=>"item_id", "default_value"=>0, "is_null_allowed"=>false, "depends_on"=>array())));
  756. }
  757. }
  758. /**
  759. * Record added/removed objects from within a link set
  760. *
  761. * @package iTopORM
  762. */
  763. class CMDBChangeOpSetAttributeLinksAddRemove extends CMDBChangeOpSetAttributeLinks
  764. {
  765. public static function Init()
  766. {
  767. $aParams = array
  768. (
  769. "category" => "core/cmdb",
  770. "key_type" => "",
  771. "name_attcode" => "change",
  772. "state_attcode" => "",
  773. "reconc_keys" => array(),
  774. "db_table" => "priv_changeop_links_addremove",
  775. "db_key_field" => "id",
  776. "db_finalclass_field" => "",
  777. );
  778. MetaModel::Init_Params($aParams);
  779. MetaModel::Init_InheritAttributes();
  780. 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())));
  781. }
  782. /**
  783. * Describe (as a text string) the modifications corresponding to this change
  784. */
  785. public function GetDescription()
  786. {
  787. $sResult = '';
  788. $oTargetObjectClass = $this->Get('objclass');
  789. $oTargetObjectKey = $this->Get('objkey');
  790. $oTargetSearch = new DBObjectSearch($oTargetObjectClass);
  791. $oTargetSearch->AddCondition('id', $oTargetObjectKey, '=');
  792. $oMonoObjectSet = new DBObjectSet($oTargetSearch);
  793. if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES)
  794. {
  795. if (!MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) return ''; // Protects against renamed attributes...
  796. $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode'));
  797. $sAttName = $oAttDef->GetLabel();
  798. $sItemDesc = MetaModel::GetHyperLink($this->Get('item_class'), $this->Get('item_id'));
  799. $sResult = $sAttName.' - ';
  800. switch ($this->Get('type'))
  801. {
  802. case 'added':
  803. $sResult .= Dict::Format('Change:LinkSet:Added', $sItemDesc);
  804. break;
  805. case 'removed':
  806. $sResult .= Dict::Format('Change:LinkSet:Removed', $sItemDesc);
  807. break;
  808. }
  809. }
  810. return $sResult;
  811. }
  812. }
  813. /**
  814. * Record attribute changes from within a link set
  815. * A single record redirects to the modifications made within the same change
  816. *
  817. * @package iTopORM
  818. */
  819. class CMDBChangeOpSetAttributeLinksTune extends CMDBChangeOpSetAttributeLinks
  820. {
  821. public static function Init()
  822. {
  823. $aParams = array
  824. (
  825. "category" => "core/cmdb",
  826. "key_type" => "",
  827. "name_attcode" => "change",
  828. "state_attcode" => "",
  829. "reconc_keys" => array(),
  830. "db_table" => "priv_changeop_links_tune",
  831. "db_key_field" => "id",
  832. "db_finalclass_field" => "",
  833. );
  834. MetaModel::Init_Params($aParams);
  835. MetaModel::Init_InheritAttributes();
  836. MetaModel::Init_AddAttribute(new AttributeInteger("link_id", array("allowed_values"=>null, "sql"=>"link_id", "default_value"=>0, "is_null_allowed"=>false, "depends_on"=>array())));
  837. }
  838. /**
  839. * Describe (as a text string) the modifications corresponding to this change
  840. */
  841. public function GetDescription()
  842. {
  843. $sResult = '';
  844. $oTargetObjectClass = $this->Get('objclass');
  845. $oTargetObjectKey = $this->Get('objkey');
  846. $oTargetSearch = new DBObjectSearch($oTargetObjectClass);
  847. $oTargetSearch->AddCondition('id', $oTargetObjectKey, '=');
  848. $oMonoObjectSet = new DBObjectSet($oTargetSearch);
  849. if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES)
  850. {
  851. if (!MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) return ''; // Protects against renamed attributes...
  852. $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode'));
  853. $sAttName = $oAttDef->GetLabel();
  854. $sLinkClass = $oAttDef->GetLinkedClass();
  855. $aLinkClasses = MetaModel::EnumChildClasses($sLinkClass, ENUM_CHILD_CLASSES_ALL);
  856. // Search for changes on the corresponding link
  857. //
  858. $oSearch = new DBObjectSearch('CMDBChangeOpSetAttribute');
  859. $oSearch->AddCondition('change', $this->Get('change'), '=');
  860. $oSearch->AddCondition('objkey', $this->Get('link_id'), '=');
  861. if (count($aLinkClasses) == 1)
  862. {
  863. // Faster than the whole building of the expression below for just one value ??
  864. $oSearch->AddCondition('objclass', $sLinkClass, '=');
  865. }
  866. else
  867. {
  868. $oField = new FieldExpression('objclass', $oSearch->GetClassAlias());
  869. $sListExpr = '('.implode(', ', CMDBSource::Quote($aLinkClasses)).')';
  870. $sOQLCondition = $oField->Render()." IN $sListExpr";
  871. $oNewCondition = Expression::FromOQL($sOQLCondition);
  872. $oSearch->AddConditionExpression($oNewCondition);
  873. }
  874. $oSet = new DBObjectSet($oSearch);
  875. $aChanges = array();
  876. while ($oChangeOp = $oSet->Fetch())
  877. {
  878. $aChanges[] = $oChangeOp->GetDescription();
  879. }
  880. if (count($aChanges) == 0)
  881. {
  882. return '';
  883. }
  884. $sItemDesc = MetaModel::GetHyperLink($this->Get('item_class'), $this->Get('item_id'));
  885. $sResult = $sAttName.' - ';
  886. $sResult .= Dict::Format('Change:LinkSet:Modified', $sItemDesc);
  887. $sResult .= ' : '.implode(', ', $aChanges);
  888. }
  889. return $sResult;
  890. }
  891. }
  892. /**
  893. * Record the modification of custom fields
  894. *
  895. * @package iTopORM
  896. */
  897. class CMDBChangeOpSetAttributeCustomFields extends CMDBChangeOpSetAttribute
  898. {
  899. public static function Init()
  900. {
  901. $aParams = array
  902. (
  903. "category" => "core/cmdb",
  904. "key_type" => "",
  905. "name_attcode" => "change",
  906. "state_attcode" => "",
  907. "reconc_keys" => array(),
  908. "db_table" => "priv_changeop_setatt_custfields",
  909. "db_key_field" => "id",
  910. "db_finalclass_field" => "",
  911. );
  912. MetaModel::Init_Params($aParams);
  913. MetaModel::Init_InheritAttributes();
  914. MetaModel::Init_AddAttribute(new AttributeLongText("prevdata", array("allowed_values"=>null, "sql"=>"prevdata", "default_value"=>"", "is_null_allowed"=>true, "depends_on"=>array())));
  915. // Display lists
  916. MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details
  917. MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list
  918. }
  919. /**
  920. * Describe (as a text string) the modifications corresponding to this change
  921. */
  922. public function GetDescription()
  923. {
  924. $sResult = '';
  925. if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode')))
  926. {
  927. $oTargetObjectClass = $this->Get('objclass');
  928. $oTargetObjectKey = $this->Get('objkey');
  929. $oTargetSearch = new DBObjectSearch($oTargetObjectClass);
  930. $oTargetSearch->AddCondition('id', $oTargetObjectKey, '=');
  931. $oMonoObjectSet = new DBObjectSet($oTargetSearch);
  932. if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES)
  933. {
  934. $aValues = json_decode($this->Get('prevdata'), true);
  935. $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode'));
  936. $sAttName = $oAttDef->GetLabel();
  937. try
  938. {
  939. $oHandler = $oAttDef->GetHandler($aValues);
  940. $sValueDesc = $oHandler->GetAsHTML($aValues);
  941. }
  942. catch (Exception $e)
  943. {
  944. $sValueDesc = 'Custom field error: '.htmlentities($e->getMessage(), ENT_QUOTES, 'UTF-8');
  945. }
  946. $sTextView = '<div>'.$sValueDesc.'</div>';
  947. $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sTextView);
  948. }
  949. }
  950. return $sResult;
  951. }
  952. }