event.class.inc.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411
  1. <?php
  2. // Copyright (C) 2010-2013 Combodo SARL
  3. //
  4. // This file is part of iTop.
  5. //
  6. // iTop is free software; you can redistribute it and/or modify
  7. // it under the terms of the GNU Affero General Public License as published by
  8. // the Free Software Foundation, either version 3 of the License, or
  9. // (at your option) any later version.
  10. //
  11. // iTop is distributed in the hope that it will be useful,
  12. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. // GNU Affero General Public License for more details.
  15. //
  16. // You should have received a copy of the GNU Affero General Public License
  17. // along with iTop. If not, see <http://www.gnu.org/licenses/>
  18. /**
  19. * Persistent class Event and derived
  20. * Application internal events
  21. * There is also a file log
  22. *
  23. * @copyright Copyright (C) 2010-2012 Combodo SARL
  24. * @license http://opensource.org/licenses/AGPL-3.0
  25. */
  26. class Event extends DBObject implements iDisplay
  27. {
  28. public static function Init()
  29. {
  30. $aParams = array
  31. (
  32. "category" => "core/cmdb,view_in_gui",
  33. "key_type" => "autoincrement",
  34. "name_attcode" => "",
  35. "state_attcode" => "",
  36. "reconc_keys" => array(),
  37. "db_table" => "priv_event",
  38. "db_key_field" => "id",
  39. "db_finalclass_field" => "realclass",
  40. "display_template" => "",
  41. "order_by_default" => array('date' => false)
  42. );
  43. MetaModel::Init_Params($aParams);
  44. //MetaModel::Init_InheritAttributes();
  45. MetaModel::Init_AddAttribute(new AttributeText("message", array("allowed_values"=>null, "sql"=>"message", "default_value"=>null, "is_null_allowed"=>false, "depends_on"=>array())));
  46. MetaModel::Init_AddAttribute(new AttributeDateTime("date", array("allowed_values"=>null, "sql"=>"date", "default_value"=>"", "is_null_allowed"=>false, "depends_on"=>array())));
  47. MetaModel::Init_AddAttribute(new AttributeString("userinfo", array("allowed_values"=>null, "sql"=>"userinfo", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array())));
  48. // MetaModel::Init_AddAttribute(new AttributeString("userinfo", array("allowed_values"=>null, "sql"=>"userinfo", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array())));
  49. // Display lists
  50. MetaModel::Init_SetZListItems('details', array('date', 'message', 'userinfo')); // Attributes to be displayed for the complete details
  51. MetaModel::Init_SetZListItems('list', array('date', 'finalclass', 'message')); // Attributes to be displayed for a list
  52. // Search criteria
  53. // MetaModel::Init_SetZListItems('standard_search', array('name')); // Criteria of the std search form
  54. // MetaModel::Init_SetZListItems('advanced_search', array('name')); // Criteria of the advanced search form
  55. }
  56. /**
  57. * Maps the given context parameter name to the appropriate filter/search code for this class
  58. * @param string $sContextParam Name of the context parameter, i.e. 'org_id'
  59. * @return string Filter code, i.e. 'customer_id'
  60. */
  61. public static function MapContextParam($sContextParam)
  62. {
  63. if ($sContextParam == 'menu')
  64. {
  65. return null;
  66. }
  67. else
  68. {
  69. return $sContextParam;
  70. }
  71. }
  72. /**
  73. * This function returns a 'hilight' CSS class, used to hilight a given row in a table
  74. * There are currently (i.e defined in the CSS) 4 possible values HILIGHT_CLASS_CRITICAL,
  75. * HILIGHT_CLASS_WARNING, HILIGHT_CLASS_OK, HILIGHT_CLASS_NONE
  76. * To Be overridden by derived classes
  77. * @param void
  78. * @return String The desired higlight class for the object/row
  79. */
  80. public function GetHilightClass()
  81. {
  82. // Possible return values are:
  83. // HILIGHT_CLASS_CRITICAL, HILIGHT_CLASS_WARNING, HILIGHT_CLASS_OK, HILIGHT_CLASS_NONE
  84. return HILIGHT_CLASS_NONE; // Not hilighted by default
  85. }
  86. public static function GetUIPage()
  87. {
  88. return 'UI.php';
  89. }
  90. function DisplayDetails(WebPage $oPage, $bEditMode = false)
  91. {
  92. // Object's details
  93. //$this->DisplayBareHeader($oPage, $bEditMode);
  94. $oPage->AddTabContainer(OBJECT_PROPERTIES_TAB);
  95. $oPage->SetCurrentTabContainer(OBJECT_PROPERTIES_TAB);
  96. $oPage->SetCurrentTab(Dict::S('UI:PropertiesTab'));
  97. $this->DisplayBareProperties($oPage, $bEditMode);
  98. }
  99. function DisplayBareProperties(WebPage $oPage, $bEditMode = false, $sPrefix = '', $aExtraParams = array())
  100. {
  101. if ($bEditMode) return array(); // Not editable
  102. $aDetails = array();
  103. $sClass = get_class($this);
  104. $aZList = MetaModel::FlattenZlist(MetaModel::GetZListItems($sClass, 'details'));
  105. foreach( $aZList as $sAttCode)
  106. {
  107. $sDisplayValue = $this->GetAsHTML($sAttCode);
  108. $aDetails[] = array('label' => '<span title="'.MetaModel::GetDescription($sClass, $sAttCode).'">'.MetaModel::GetLabel($sClass, $sAttCode).'</span>', 'value' => $sDisplayValue);
  109. }
  110. $oPage->Details($aDetails);
  111. return array();
  112. }
  113. }
  114. class EventNotification extends Event
  115. {
  116. public static function Init()
  117. {
  118. $aParams = array
  119. (
  120. "category" => "core/cmdb,view_in_gui",
  121. "key_type" => "autoincrement",
  122. "name_attcode" => "",
  123. "state_attcode" => "",
  124. "reconc_keys" => array(),
  125. "db_table" => "priv_event_notification",
  126. "db_key_field" => "id",
  127. "db_finalclass_field" => "",
  128. "display_template" => "",
  129. "order_by_default" => array('date' => false),
  130. 'indexes' => array(
  131. array('object_id'),
  132. )
  133. );
  134. MetaModel::Init_Params($aParams);
  135. MetaModel::Init_InheritAttributes();
  136. MetaModel::Init_AddAttribute(new AttributeExternalKey("trigger_id", array("targetclass"=>"Trigger", "jointype"=> "", "allowed_values"=>null, "sql"=>"trigger_id", "is_null_allowed"=>false, "on_target_delete"=>DEL_AUTO, "depends_on"=>array())));
  137. MetaModel::Init_AddAttribute(new AttributeExternalKey("action_id", array("targetclass"=>"Action", "jointype"=> "", "allowed_values"=>null, "sql"=>"action_id", "is_null_allowed"=>false, "on_target_delete"=>DEL_AUTO, "depends_on"=>array())));
  138. MetaModel::Init_AddAttribute(new AttributeInteger("object_id", array("allowed_values"=>null, "sql"=>"object_id", "default_value"=>0, "is_null_allowed"=>false, "depends_on"=>array())));
  139. // Display lists
  140. MetaModel::Init_SetZListItems('details', array('date', 'message', 'userinfo', 'trigger_id', 'action_id', 'object_id')); // Attributes to be displayed for the complete details
  141. MetaModel::Init_SetZListItems('list', array('date', 'message')); // Attributes to be displayed for a list
  142. // Search criteria
  143. // MetaModel::Init_SetZListItems('standard_search', array('name')); // Criteria of the std search form
  144. // MetaModel::Init_SetZListItems('advanced_search', array('name')); // Criteria of the advanced search form
  145. }
  146. }
  147. class EventNotificationEmail extends EventNotification
  148. {
  149. public static function Init()
  150. {
  151. $aParams = array
  152. (
  153. "category" => "core/cmdb,view_in_gui",
  154. "key_type" => "autoincrement",
  155. "name_attcode" => "",
  156. "state_attcode" => "",
  157. "reconc_keys" => array(),
  158. "db_table" => "priv_event_email",
  159. "db_key_field" => "id",
  160. "db_finalclass_field" => "",
  161. "display_template" => "",
  162. "order_by_default" => array('date' => false)
  163. );
  164. MetaModel::Init_Params($aParams);
  165. MetaModel::Init_InheritAttributes();
  166. MetaModel::Init_AddAttribute(new AttributeText("to", array("allowed_values"=>null, "sql"=>"to", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array())));
  167. MetaModel::Init_AddAttribute(new AttributeText("cc", array("allowed_values"=>null, "sql"=>"cc", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array())));
  168. MetaModel::Init_AddAttribute(new AttributeText("bcc", array("allowed_values"=>null, "sql"=>"bcc", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array())));
  169. MetaModel::Init_AddAttribute(new AttributeText("from", array("allowed_values"=>null, "sql"=>"from", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array())));
  170. MetaModel::Init_AddAttribute(new AttributeText("subject", array("allowed_values"=>null, "sql"=>"subject", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array())));
  171. MetaModel::Init_AddAttribute(new AttributeHTML("body", array("allowed_values"=>null, "sql"=>"body", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array())));
  172. MetaModel::Init_AddAttribute(new AttributeTable("attachments", array("allowed_values"=>null, "sql"=>"attachments", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array())));
  173. // Display lists
  174. MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'message', 'trigger_id', 'action_id', 'object_id', 'to', 'cc', 'bcc', 'from', 'subject', 'body', 'attachments')); // Attributes to be displayed for the complete details
  175. MetaModel::Init_SetZListItems('list', array('date', 'message', 'to', 'subject', 'attachments')); // Attributes to be displayed for a list
  176. // Search criteria
  177. // MetaModel::Init_SetZListItems('standard_search', array('name')); // Criteria of the std search form
  178. // MetaModel::Init_SetZListItems('advanced_search', array('name')); // Criteria of the advanced search form
  179. }
  180. }
  181. class EventIssue extends Event
  182. {
  183. public static function Init()
  184. {
  185. $aParams = array
  186. (
  187. "category" => "core/cmdb,view_in_gui",
  188. "key_type" => "autoincrement",
  189. "name_attcode" => "",
  190. "state_attcode" => "",
  191. "reconc_keys" => array(),
  192. "db_table" => "priv_event_issue",
  193. "db_key_field" => "id",
  194. "db_finalclass_field" => "",
  195. "display_template" => "",
  196. "order_by_default" => array('date' => false)
  197. );
  198. MetaModel::Init_Params($aParams);
  199. MetaModel::Init_InheritAttributes();
  200. MetaModel::Init_AddAttribute(new AttributeString("issue", array("allowed_values"=>null, "sql"=>"issue", "default_value"=>null, "is_null_allowed"=>false, "depends_on"=>array())));
  201. MetaModel::Init_AddAttribute(new AttributeString("impact", array("allowed_values"=>null, "sql"=>"impact", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array())));
  202. MetaModel::Init_AddAttribute(new AttributeString("page", array("allowed_values"=>null, "sql"=>"page", "default_value"=>null, "is_null_allowed"=>false, "depends_on"=>array())));
  203. MetaModel::Init_AddAttribute(new AttributePropertySet("arguments_post", array("allowed_values"=>null, "sql"=>"arguments_post", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array())));
  204. MetaModel::Init_AddAttribute(new AttributePropertySet("arguments_get", array("allowed_values"=>null, "sql"=>"arguments_get", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array())));
  205. MetaModel::Init_AddAttribute(new AttributeTable("callstack", array("allowed_values"=>null, "sql"=>"callstack", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array())));
  206. MetaModel::Init_AddAttribute(new AttributePropertySet("data", array("allowed_values"=>null, "sql"=>"data", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array())));
  207. // Display lists
  208. MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'issue', 'impact', 'page', 'arguments_post', 'arguments_get', 'callstack', 'data')); // Attributes to be displayed for the complete details
  209. MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'issue', 'impact')); // Attributes to be displayed for a list
  210. // Search criteria
  211. // MetaModel::Init_SetZListItems('standard_search', array('name')); // Criteria of the std search form
  212. // MetaModel::Init_SetZListItems('advanced_search', array('name')); // Criteria of the advanced search form
  213. }
  214. protected function OnInsert()
  215. {
  216. // Init page information: name, arguments
  217. //
  218. $this->Set('page', @$GLOBALS['_SERVER']['SCRIPT_NAME']);
  219. if (array_key_exists('_GET', $GLOBALS) && is_array($GLOBALS['_GET']))
  220. {
  221. $this->Set('arguments_get', $GLOBALS['_GET']);
  222. }
  223. else
  224. {
  225. $this->Set('arguments_get', array());
  226. }
  227. if (array_key_exists('_POST', $GLOBALS) && is_array($GLOBALS['_POST']))
  228. {
  229. $aPost = array();
  230. foreach($GLOBALS['_POST'] as $sKey => $sValue)
  231. {
  232. if (is_string($sValue))
  233. {
  234. if (strlen($sValue) < 256)
  235. {
  236. $aPost[$sKey] = $sValue;
  237. }
  238. else
  239. {
  240. $aPost[$sKey] = "!long string: ".strlen($sValue). " chars";
  241. }
  242. }
  243. else
  244. {
  245. // Not a string
  246. $aPost[$sKey] = (string) $sValue;
  247. }
  248. }
  249. $this->Set('arguments_post', $aPost);
  250. }
  251. else
  252. {
  253. $this->Set('arguments_post', array());
  254. }
  255. $sLength = strlen($this->Get('issue'));
  256. if ($sLength > 255)
  257. {
  258. $this->Set('issue', substr($this->Get('issue'), 0, 200)." -truncated ($sLength chars)");
  259. }
  260. $sLength = strlen($this->Get('impact'));
  261. if ($sLength > 255)
  262. {
  263. $this->Set('impact', substr($this->Get('impact'), 0, 200)." -truncated ($sLength chars)");
  264. }
  265. $sLength = strlen($this->Get('page'));
  266. if ($sLength > 255)
  267. {
  268. $this->Set('page', substr($this->Get('page'), 0, 200)." -truncated ($sLength chars)");
  269. }
  270. }
  271. }
  272. class EventWebService extends Event
  273. {
  274. public static function Init()
  275. {
  276. $aParams = array
  277. (
  278. "category" => "core/cmdb,view_in_gui",
  279. "key_type" => "autoincrement",
  280. "name_attcode" => "",
  281. "state_attcode" => "",
  282. "reconc_keys" => array(),
  283. "db_table" => "priv_event_webservice",
  284. "db_key_field" => "id",
  285. "db_finalclass_field" => "",
  286. "display_template" => "",
  287. "order_by_default" => array('date' => false)
  288. );
  289. MetaModel::Init_Params($aParams);
  290. MetaModel::Init_InheritAttributes();
  291. MetaModel::Init_AddAttribute(new AttributeString("verb", array("allowed_values"=>null, "sql"=>"verb", "default_value"=>null, "is_null_allowed"=>false, "depends_on"=>array())));
  292. //MetaModel::Init_AddAttribute(new AttributeStructure("arguments", array("allowed_values"=>null, "sql"=>"data", "default_value"=>null, "is_null_allowed"=>false, "depends_on"=>array())));
  293. MetaModel::Init_AddAttribute(new AttributeBoolean("result", array("allowed_values"=>null, "sql"=>"result", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array())));
  294. MetaModel::Init_AddAttribute(new AttributeText("log_info", array("allowed_values"=>null, "sql"=>"log_info", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array())));
  295. MetaModel::Init_AddAttribute(new AttributeText("log_warning", array("allowed_values"=>null, "sql"=>"log_warning", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array())));
  296. MetaModel::Init_AddAttribute(new AttributeText("log_error", array("allowed_values"=>null, "sql"=>"log_error", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array())));
  297. MetaModel::Init_AddAttribute(new AttributeText("data", array("allowed_values"=>null, "sql"=>"data", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array())));
  298. // Display lists
  299. MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'verb', 'result', 'log_info', 'log_warning', 'log_error', 'data')); // Attributes to be displayed for the complete details
  300. MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'verb', 'result')); // Attributes to be displayed for a list
  301. // Search criteria
  302. // MetaModel::Init_SetZListItems('standard_search', array('name')); // Criteria of the std search form
  303. // MetaModel::Init_SetZListItems('advanced_search', array('name')); // Criteria of the advanced search form
  304. }
  305. }
  306. class EventRestService extends Event
  307. {
  308. public static function Init()
  309. {
  310. $aParams = array
  311. (
  312. "category" => "core/cmdb,view_in_gui",
  313. "key_type" => "autoincrement",
  314. "name_attcode" => "",
  315. "state_attcode" => "",
  316. "reconc_keys" => array(),
  317. "db_table" => "priv_event_restservice",
  318. "db_key_field" => "id",
  319. "db_finalclass_field" => "",
  320. "display_template" => "",
  321. "order_by_default" => array('date' => false)
  322. );
  323. MetaModel::Init_Params($aParams);
  324. MetaModel::Init_InheritAttributes();
  325. MetaModel::Init_AddAttribute(new AttributeString("operation", array("allowed_values"=>null, "sql"=>"operation", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array())));
  326. MetaModel::Init_AddAttribute(new AttributeString("version", array("allowed_values"=>null, "sql"=>"version", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array())));
  327. MetaModel::Init_AddAttribute(new AttributeText("json_input", array("allowed_values"=>null, "sql"=>"json_input", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array())));
  328. MetaModel::Init_AddAttribute(new AttributeInteger("code", array("allowed_values"=>null, "sql"=>"code", "default_value"=>0, "is_null_allowed"=>false, "depends_on"=>array())));
  329. MetaModel::Init_AddAttribute(new AttributeText("json_output", array("allowed_values"=>null, "sql"=>"json_output", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array())));
  330. MetaModel::Init_AddAttribute(new AttributeString("provider", array("allowed_values"=>null, "sql"=>"provider", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array())));
  331. // Display lists
  332. MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'operation', 'version', 'json_input', 'message', 'code', 'json_output', 'provider')); // Attributes to be displayed for the complete details
  333. MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'operation', 'message')); // Attributes to be displayed for a list
  334. // Search criteria
  335. // MetaModel::Init_SetZListItems('standard_search', array('name')); // Criteria of the std search form
  336. // MetaModel::Init_SetZListItems('advanced_search', array('name')); // Criteria of the advanced search form
  337. }
  338. }
  339. class EventLoginUsage extends Event
  340. {
  341. public static function Init()
  342. {
  343. $aParams = array
  344. (
  345. "category" => "core/cmdb,view_in_gui",
  346. "key_type" => "autoincrement",
  347. "name_attcode" => "",
  348. "state_attcode" => "",
  349. "reconc_keys" => array(),
  350. "db_table" => "priv_event_loginusage",
  351. "db_key_field" => "id",
  352. "db_finalclass_field" => "",
  353. "order_by_default" => array('date' => false)
  354. );
  355. MetaModel::Init_Params($aParams);
  356. MetaModel::Init_InheritAttributes();
  357. MetaModel::Init_AddAttribute(new AttributeExternalKey("user_id", array("targetclass"=>"User", "jointype"=> "", "allowed_values"=>null, "sql"=>"user_id", "is_null_allowed"=>false, "on_target_delete"=>DEL_SILENT, "depends_on"=>array())));
  358. $aZList = array('date', 'user_id');
  359. if (MetaModel::IsValidAttCode('Contact', 'name'))
  360. {
  361. MetaModel::Init_AddAttribute(new AttributeExternalField("contact_name", array("allowed_values"=>null, "extkey_attcode"=>"user_id", "target_attcode"=>"contactid", "is_null_allowed"=>true, "depends_on"=>array())));
  362. $aZList[] = 'contact_name';
  363. }
  364. if (MetaModel::IsValidAttCode('Contact', 'email'))
  365. {
  366. MetaModel::Init_AddAttribute(new AttributeExternalField("contact_email", array("allowed_values"=>null, "extkey_attcode"=>"user_id", "target_attcode"=>"email", "is_null_allowed"=>true, "depends_on"=>array())));
  367. $aZList[] = 'contact_email';
  368. }
  369. // Display lists
  370. MetaModel::Init_SetZListItems('details', array_merge($aZList, array('userinfo', 'message'))); // Attributes to be displayed for the complete details
  371. MetaModel::Init_SetZListItems('list', array_merge($aZList, array('userinfo'))); // Attributes to be displayed for a list
  372. // Search criteria
  373. MetaModel::Init_SetZListItems('standard_search', $aZList); // Criteria of the std search form
  374. // MetaModel::Init_SetZListItems('advanced_search', array('name')); // Criteria of the advanced search form
  375. }
  376. }
  377. ?>