cmdbchangeop.class.inc.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610
  1. <?php
  2. // Copyright (C) 2010 Combodo SARL
  3. //
  4. // This program is free software; you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation; version 3 of the License.
  7. //
  8. // This program is distributed in the hope that it will be useful,
  9. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. // GNU General Public License for more details.
  12. //
  13. // You should have received a copy of the GNU General Public License
  14. // along with this program; if not, write to the Free Software
  15. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  16. /**
  17. * Persistent classes (internal) : cmdbChangeOp and derived
  18. *
  19. * @author Erwan Taloc <erwan.taloc@combodo.com>
  20. * @author Romain Quetiez <romain.quetiez@combodo.com>
  21. * @author Denis Flaven <denis.flaven@combodo.com>
  22. * @license http://www.opensource.org/licenses/gpl-3.0.html LGPL
  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. );
  44. MetaModel::Init_Params($aParams);
  45. //MetaModel::Init_InheritAttributes();
  46. 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())));
  47. MetaModel::Init_AddAttribute(new AttributeExternalField("date", array("allowed_values"=>null, "extkey_attcode"=>"change", "target_attcode"=>"date")));
  48. MetaModel::Init_AddAttribute(new AttributeExternalField("userinfo", array("allowed_values"=>null, "extkey_attcode"=>"change", "target_attcode"=>"userinfo")));
  49. MetaModel::Init_AddAttribute(new AttributeString("objclass", array("allowed_values"=>null, "sql"=>"objclass", "default_value"=>"", "is_null_allowed"=>false, "depends_on"=>array())));
  50. MetaModel::Init_AddAttribute(new AttributeString("objkey", array("allowed_values"=>null, "sql"=>"objkey", "default_value"=>"", "is_null_allowed"=>false, "depends_on"=>array())));
  51. MetaModel::Init_SetZListItems('details', array('change', 'date', 'userinfo')); // Attributes to be displayed for the complete details
  52. MetaModel::Init_SetZListItems('list', array('change', 'date', 'userinfo')); // Attributes to be displayed for the complete details
  53. }
  54. /**
  55. * Describe (as a text string) the modifications corresponding to this change
  56. */
  57. public function GetDescription()
  58. {
  59. return '';
  60. }
  61. }
  62. /**
  63. * Record the creation of an object
  64. *
  65. * @package iTopORM
  66. */
  67. class CMDBChangeOpCreate extends CMDBChangeOp
  68. {
  69. public static function Init()
  70. {
  71. $aParams = array
  72. (
  73. "category" => "core/cmdb",
  74. "key_type" => "",
  75. "name_attcode" => "change",
  76. "state_attcode" => "",
  77. "reconc_keys" => array(),
  78. "db_table" => "priv_changeop_create",
  79. "db_key_field" => "id",
  80. "db_finalclass_field" => "",
  81. );
  82. MetaModel::Init_Params($aParams);
  83. MetaModel::Init_InheritAttributes();
  84. }
  85. /**
  86. * Describe (as a text string) the modifications corresponding to this change
  87. */
  88. public function GetDescription()
  89. {
  90. return Dict::S('Change:ObjectCreated');
  91. }
  92. }
  93. /**
  94. * Record the deletion of an object
  95. *
  96. * @package iTopORM
  97. */
  98. class CMDBChangeOpDelete extends CMDBChangeOp
  99. {
  100. public static function Init()
  101. {
  102. $aParams = array
  103. (
  104. "category" => "core/cmdb",
  105. "key_type" => "",
  106. "name_attcode" => "change",
  107. "state_attcode" => "",
  108. "reconc_keys" => array(),
  109. "db_table" => "priv_changeop_delete",
  110. "db_key_field" => "id",
  111. "db_finalclass_field" => "",
  112. );
  113. MetaModel::Init_Params($aParams);
  114. MetaModel::Init_InheritAttributes();
  115. }
  116. /**
  117. * Describe (as a text string) the modifications corresponding to this change
  118. */
  119. public function GetDescription()
  120. {
  121. return Dict::S('Change:ObjectDeleted');
  122. }
  123. }
  124. /**
  125. * Record the modification of an attribute (abstract)
  126. *
  127. * @package iTopORM
  128. */
  129. class CMDBChangeOpSetAttribute extends CMDBChangeOp
  130. {
  131. public static function Init()
  132. {
  133. $aParams = array
  134. (
  135. "category" => "core/cmdb",
  136. "key_type" => "",
  137. "name_attcode" => "change",
  138. "state_attcode" => "",
  139. "reconc_keys" => array(),
  140. "db_table" => "priv_changeop_setatt",
  141. "db_key_field" => "id",
  142. "db_finalclass_field" => "",
  143. );
  144. MetaModel::Init_Params($aParams);
  145. MetaModel::Init_InheritAttributes();
  146. MetaModel::Init_AddAttribute(new AttributeString("attcode", array("allowed_values"=>null, "sql"=>"attcode", "default_value"=>"", "is_null_allowed"=>false, "depends_on"=>array())));
  147. // Display lists
  148. MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details
  149. MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list
  150. }
  151. }
  152. /**
  153. * Record the modification of a scalar attribute
  154. *
  155. * @package iTopORM
  156. */
  157. class CMDBChangeOpSetAttributeScalar extends CMDBChangeOpSetAttribute
  158. {
  159. public static function Init()
  160. {
  161. $aParams = array
  162. (
  163. "category" => "core/cmdb",
  164. "key_type" => "",
  165. "name_attcode" => "change",
  166. "state_attcode" => "",
  167. "reconc_keys" => array(),
  168. "db_table" => "priv_changeop_setatt_scalar",
  169. "db_key_field" => "id",
  170. "db_finalclass_field" => "",
  171. );
  172. MetaModel::Init_Params($aParams);
  173. MetaModel::Init_InheritAttributes();
  174. MetaModel::Init_AddAttribute(new AttributeString("oldvalue", array("allowed_values"=>null, "sql"=>"oldvalue", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array())));
  175. MetaModel::Init_AddAttribute(new AttributeString("newvalue", array("allowed_values"=>null, "sql"=>"newvalue", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array())));
  176. // Display lists
  177. MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode', 'oldvalue', 'newvalue')); // Attributes to be displayed for the complete details
  178. MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode', 'oldvalue', 'newvalue')); // Attributes to be displayed for a list
  179. }
  180. /**
  181. * Describe (as a text string) the modifications corresponding to this change
  182. */
  183. public function GetDescription()
  184. {
  185. // Temporary, until we change the options of GetDescription() -needs a more global revision
  186. $bIsHtml = true;
  187. $sResult = '';
  188. $oTargetObjectClass = $this->Get('objclass');
  189. $oTargetObjectKey = $this->Get('objkey');
  190. $oTargetSearch = new DBObjectSearch($oTargetObjectClass);
  191. $oTargetSearch->AddCondition('id', $oTargetObjectKey, '=');
  192. $oMonoObjectSet = new DBObjectSet($oTargetSearch);
  193. if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES)
  194. {
  195. if (!MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) return ''; // Protects against renamed attributes...
  196. $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode'));
  197. $sAttName = $oAttDef->GetLabel();
  198. $sNewValue = $this->Get('newvalue');
  199. $sOldValue = $this->Get('oldvalue');
  200. if ($oAttDef instanceof AttributeEnum)
  201. {
  202. // translate the enum values
  203. $sOldValue = $oAttDef->GetAsHTML($sOldValue);
  204. $sNewValue = $oAttDef->GetAsHTML($sNewValue);
  205. if (strlen($sOldValue) == 0)
  206. {
  207. $sResult = Dict::Format('Change:AttName_SetTo', $sAttName, $sNewValue);
  208. }
  209. else
  210. {
  211. $sResult = Dict::Format('Change:AttName_SetTo_NewValue_PreviousValue_OldValue', $sAttName, $sNewValue, $sOldValue);
  212. }
  213. }
  214. elseif ( (($oAttDef->GetType() == 'String') || ($oAttDef->GetType() == 'Text')) &&
  215. (strlen($sNewValue) > strlen($sOldValue)) )
  216. {
  217. // Check if some text was not appended to the field
  218. if (substr($sNewValue,0, strlen($sOldValue)) == $sOldValue) // Text added at the end
  219. {
  220. $sDelta = substr($sNewValue, strlen($sOldValue));
  221. $sResult = Dict::Format('Change:Text_AppendedTo_AttName', $sDelta, $sAttName);
  222. }
  223. else if (substr($sNewValue, -strlen($sOldValue)) == $sOldValue) // Text added at the beginning
  224. {
  225. $sDelta = substr($sNewValue, 0, strlen($sNewValue) - strlen($sOldValue));
  226. $sResult = Dict::Format('Change:Text_AppendedTo_AttName', $sDelta, $sAttName);
  227. }
  228. else
  229. {
  230. if (strlen($sOldValue) == 0)
  231. {
  232. $sResult = Dict::Format('Change:AttName_SetTo', $sAttName, $sNewValue);
  233. }
  234. else
  235. {
  236. $sResult = Dict::Format('Change:AttName_SetTo_NewValue_PreviousValue_OldValue', $sAttName, $sNewValue, $sOldValue);
  237. }
  238. }
  239. }
  240. elseif($bIsHtml && $oAttDef->IsExternalKey())
  241. {
  242. $sTargetClass = $oAttDef->GetTargetClass();
  243. $sFrom = MetaModel::GetHyperLink($sTargetClass, $sOldValue);
  244. $sTo = MetaModel::GetHyperLink($sTargetClass, $sNewValue);
  245. $sResult = "$sAttName set to $sTo (previous: $sFrom)";
  246. if (strlen($sFrom) == 0)
  247. {
  248. $sResult = Dict::Format('Change:AttName_SetTo', $sAttName, $sTo);
  249. }
  250. else
  251. {
  252. $sResult = Dict::Format('Change:AttName_SetTo_NewValue_PreviousValue_OldValue', $sAttName, $sTo, $sFrom);
  253. }
  254. }
  255. elseif ($oAttDef instanceOf AttributeBlob)
  256. {
  257. $sResult = "#@# Issue... found an attribute for which other type of tracking should be made";
  258. }
  259. else
  260. {
  261. if (strlen($sOldValue) == 0)
  262. {
  263. $sResult = Dict::Format('Change:AttName_SetTo', $sAttName, $sNewValue);
  264. }
  265. else
  266. {
  267. $sResult = Dict::Format('Change:AttName_SetTo_NewValue_PreviousValue_OldValue', $sAttName, $sNewValue, $sOldValue);
  268. }
  269. }
  270. }
  271. return $sResult;
  272. }
  273. }
  274. /**
  275. * Record the modification of a blob
  276. *
  277. * @package iTopORM
  278. */
  279. class CMDBChangeOpSetAttributeBlob extends CMDBChangeOpSetAttribute
  280. {
  281. public static function Init()
  282. {
  283. $aParams = array
  284. (
  285. "category" => "core/cmdb",
  286. "key_type" => "",
  287. "name_attcode" => "change",
  288. "state_attcode" => "",
  289. "reconc_keys" => array(),
  290. "db_table" => "priv_changeop_setatt_data",
  291. "db_key_field" => "id",
  292. "db_finalclass_field" => "",
  293. );
  294. MetaModel::Init_Params($aParams);
  295. MetaModel::Init_InheritAttributes();
  296. MetaModel::Init_AddAttribute(new AttributeBlob("prevdata", array("depends_on"=>array())));
  297. // Display lists
  298. MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details
  299. MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list
  300. }
  301. /**
  302. * Describe (as a text string) the modifications corresponding to this change
  303. */
  304. public function GetDescription()
  305. {
  306. // Temporary, until we change the options of GetDescription() -needs a more global revision
  307. $bIsHtml = true;
  308. $sResult = '';
  309. $oTargetObjectClass = $this->Get('objclass');
  310. $oTargetObjectKey = $this->Get('objkey');
  311. $oTargetSearch = new DBObjectSearch($oTargetObjectClass);
  312. $oTargetSearch->AddCondition('id', $oTargetObjectKey, '=');
  313. $oMonoObjectSet = new DBObjectSet($oTargetSearch);
  314. if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES)
  315. {
  316. $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode'));
  317. $sAttName = $oAttDef->GetLabel();
  318. $oPrevDoc = $this->Get('prevdata');
  319. $sDocView = $oPrevDoc->GetAsHtml();
  320. $sDocView .= "<br/>".Dict::Format('UI:OpenDocumentInNewWindow_',$oPrevDoc->GetDisplayLink(get_class($this), $this->GetKey(), 'prevdata')).", \n";
  321. $sDocView .= Dict::Format('UI:DownloadDocument_', $oPrevDoc->GetDownloadLink(get_class($this), $this->GetKey(), 'prevdata'))."\n";
  322. //$sDocView = $oPrevDoc->GetDisplayInline(get_class($this), $this->GetKey(), 'prevdata');
  323. $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sDocView);
  324. }
  325. return $sResult;
  326. }
  327. }
  328. /**
  329. * Safely record the modification of one way encrypted password
  330. */
  331. class CMDBChangeOpSetAttributeOneWayPassword extends CMDBChangeOpSetAttribute
  332. {
  333. public static function Init()
  334. {
  335. $aParams = array
  336. (
  337. "category" => "core/cmdb",
  338. "key_type" => "",
  339. "name_attcode" => "change",
  340. "state_attcode" => "",
  341. "reconc_keys" => array(),
  342. "db_table" => "priv_changeop_setatt_pwd",
  343. "db_key_field" => "id",
  344. "db_finalclass_field" => "",
  345. );
  346. MetaModel::Init_Params($aParams);
  347. MetaModel::Init_InheritAttributes();
  348. MetaModel::Init_AddAttribute(new AttributeOneWayPassword("prev_pwd", array("sql" => 'data', "default_value" => '', "is_null_allowed"=> true, "allowed_values" => null, "depends_on"=>array())));
  349. // Display lists
  350. MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details
  351. MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list
  352. }
  353. /**
  354. * Describe (as a text string) the modifications corresponding to this change
  355. */
  356. public function GetDescription()
  357. {
  358. // Temporary, until we change the options of GetDescription() -needs a more global revision
  359. $bIsHtml = true;
  360. $sResult = '';
  361. $oTargetObjectClass = $this->Get('objclass');
  362. $oTargetObjectKey = $this->Get('objkey');
  363. $oTargetSearch = new DBObjectSearch($oTargetObjectClass);
  364. $oTargetSearch->AddCondition('id', $oTargetObjectKey, '=');
  365. $oMonoObjectSet = new DBObjectSet($oTargetSearch);
  366. if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES)
  367. {
  368. $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode'));
  369. $sAttName = $oAttDef->GetLabel();
  370. $sResult = Dict::Format('Change:AttName_Changed', $sAttName);
  371. }
  372. return $sResult;
  373. }
  374. }
  375. /**
  376. * Safely record the modification of an encrypted field
  377. */
  378. class CMDBChangeOpSetAttributeEncrypted extends CMDBChangeOpSetAttribute
  379. {
  380. public static function Init()
  381. {
  382. $aParams = array
  383. (
  384. "category" => "core/cmdb",
  385. "key_type" => "",
  386. "name_attcode" => "change",
  387. "state_attcode" => "",
  388. "reconc_keys" => array(),
  389. "db_table" => "priv_changeop_setatt_encrypted",
  390. "db_key_field" => "id",
  391. "db_finalclass_field" => "",
  392. );
  393. MetaModel::Init_Params($aParams);
  394. MetaModel::Init_InheritAttributes();
  395. MetaModel::Init_AddAttribute(new AttributeEncryptedString("prevstring", array("sql" => 'data', "default_value" => '', "is_null_allowed"=> true, "allowed_values" => null, "depends_on"=>array())));
  396. // Display lists
  397. MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details
  398. MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list
  399. }
  400. /**
  401. * Describe (as a text string) the modifications corresponding to this change
  402. */
  403. public function GetDescription()
  404. {
  405. // Temporary, until we change the options of GetDescription() -needs a more global revision
  406. $bIsHtml = true;
  407. $sResult = '';
  408. $oTargetObjectClass = $this->Get('objclass');
  409. $oTargetObjectKey = $this->Get('objkey');
  410. $oTargetSearch = new DBObjectSearch($oTargetObjectClass);
  411. $oTargetSearch->AddCondition('id', $oTargetObjectKey, '=');
  412. $oMonoObjectSet = new DBObjectSet($oTargetSearch);
  413. if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES)
  414. {
  415. $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode'));
  416. $sAttName = $oAttDef->GetLabel();
  417. $sPrevString = $this->Get('prevstring');
  418. $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sPrevString);
  419. }
  420. return $sResult;
  421. }
  422. }
  423. /**
  424. * Record the modification of a multiline string (text)
  425. *
  426. * @package iTopORM
  427. */
  428. class CMDBChangeOpSetAttributeText extends CMDBChangeOpSetAttribute
  429. {
  430. public static function Init()
  431. {
  432. $aParams = array
  433. (
  434. "category" => "core/cmdb",
  435. "key_type" => "",
  436. "name_attcode" => "change",
  437. "state_attcode" => "",
  438. "reconc_keys" => array(),
  439. "db_table" => "priv_changeop_setatt_text",
  440. "db_key_field" => "id",
  441. "db_finalclass_field" => "",
  442. );
  443. MetaModel::Init_Params($aParams);
  444. MetaModel::Init_InheritAttributes();
  445. MetaModel::Init_AddAttribute(new AttributeText("prevdata", array("allowed_values"=>null, "sql"=>"prevdata", "default_value"=>"", "is_null_allowed"=>true, "depends_on"=>array())));
  446. // Display lists
  447. MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details
  448. MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list
  449. }
  450. /**
  451. * Describe (as a text string) the modifications corresponding to this change
  452. */
  453. public function GetDescription()
  454. {
  455. // Temporary, until we change the options of GetDescription() -needs a more global revision
  456. $bIsHtml = true;
  457. $sResult = '';
  458. $oTargetObjectClass = $this->Get('objclass');
  459. $oTargetObjectKey = $this->Get('objkey');
  460. $oTargetSearch = new DBObjectSearch($oTargetObjectClass);
  461. $oTargetSearch->AddCondition('id', $oTargetObjectKey, '=');
  462. $oMonoObjectSet = new DBObjectSet($oTargetSearch);
  463. if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES)
  464. {
  465. $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode'));
  466. $sAttName = $oAttDef->GetLabel();
  467. $sTextView = '<div>'.$this->GetAsHtml('prevdata').'</div>';
  468. //$sDocView = $oPrevDoc->GetDisplayInline(get_class($this), $this->GetKey(), 'prevdata');
  469. $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sTextView);
  470. }
  471. return $sResult;
  472. }
  473. }
  474. /**
  475. * Record the modification of a caselog (text)
  476. * since the caselog itself stores the history
  477. * of its entries, there is no need to duplicate
  478. * the text here
  479. *
  480. * @package iTopORM
  481. */
  482. class CMDBChangeOpSetAttributeCaseLog extends CMDBChangeOpSetAttribute
  483. {
  484. public static function Init()
  485. {
  486. $aParams = array
  487. (
  488. "category" => "core/cmdb",
  489. "key_type" => "",
  490. "name_attcode" => "change",
  491. "state_attcode" => "",
  492. "reconc_keys" => array(),
  493. "db_table" => "priv_changeop_setatt_log",
  494. "db_key_field" => "id",
  495. "db_finalclass_field" => "",
  496. );
  497. MetaModel::Init_Params($aParams);
  498. MetaModel::Init_InheritAttributes();
  499. MetaModel::Init_AddAttribute(new AttributeInteger("lastentry", array("allowed_values"=>null, "sql"=>"lastentry", "default_value"=>0, "is_null_allowed"=>true, "depends_on"=>array())));
  500. // Display lists
  501. MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details
  502. MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list
  503. }
  504. /**
  505. * Describe (as a text string) the modifications corresponding to this change
  506. */
  507. public function GetDescription()
  508. {
  509. // Temporary, until we change the options of GetDescription() -needs a more global revision
  510. $bIsHtml = true;
  511. $sResult = '';
  512. $oTargetObjectClass = $this->Get('objclass');
  513. $oTargetObjectKey = $this->Get('objkey');
  514. $oTargetSearch = new DBObjectSearch($oTargetObjectClass);
  515. $oTargetSearch->AddCondition('id', $oTargetObjectKey, '=');
  516. $oMonoObjectSet = new DBObjectSet($oTargetSearch);
  517. if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES)
  518. {
  519. $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode'));
  520. $sAttName = $oAttDef->GetLabel();
  521. $sResult = Dict::Format('Change:AttName_EntryAdded', $sAttName);
  522. }
  523. return $sResult;
  524. }
  525. }
  526. /**
  527. * Record an action made by a plug-in
  528. *
  529. * @package iTopORM
  530. */
  531. class CMDBChangeOpPlugin extends CMDBChangeOp
  532. {
  533. public static function Init()
  534. {
  535. $aParams = array
  536. (
  537. "category" => "core/cmdb",
  538. "key_type" => "",
  539. "name_attcode" => "change",
  540. "state_attcode" => "",
  541. "reconc_keys" => array(),
  542. "db_table" => "priv_changeop_plugin",
  543. "db_key_field" => "id",
  544. "db_finalclass_field" => "",
  545. );
  546. MetaModel::Init_Params($aParams);
  547. MetaModel::Init_AddAttribute(new AttributeString("description", array("allowed_values"=>null, "sql"=>"description", "default_value"=>'', "is_null_allowed"=>false, "depends_on"=>array())));
  548. /* 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
  549. MetaModel::Init_AddAttribute(new AttributeString("extension_class", array("allowed_values"=>null, "sql"=>"extension_class", "default_value"=>'', "is_null_allowed"=>false, "depends_on"=>array())));
  550. MetaModel::Init_AddAttribute(new AttributeInteger("extension_id", array("allowed_values"=>null, "sql"=>"extension_id", "default_value"=>0, "is_null_allowed"=>false, "depends_on"=>array())));
  551. */
  552. MetaModel::Init_InheritAttributes();
  553. }
  554. /**
  555. * Describe (as a text string) the modifications corresponding to this change
  556. */
  557. public function GetDescription()
  558. {
  559. return $this->Get('description');
  560. }
  561. }
  562. ?>