cmdbchangeop.class.inc.php 37 KB

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