event.class.inc.php 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371
  1. <?php
  2. // Copyright (C) 2010-2012 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; // 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. }
  112. }
  113. class EventNotification extends Event
  114. {
  115. public static function Init()
  116. {
  117. $aParams = array
  118. (
  119. "category" => "core/cmdb,view_in_gui",
  120. "key_type" => "autoincrement",
  121. "name_attcode" => "",
  122. "state_attcode" => "",
  123. "reconc_keys" => array(),
  124. "db_table" => "priv_event_notification",
  125. "db_key_field" => "id",
  126. "db_finalclass_field" => "",
  127. "display_template" => "",
  128. "order_by_default" => array('date' => false)
  129. );
  130. MetaModel::Init_Params($aParams);
  131. MetaModel::Init_InheritAttributes();
  132. 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())));
  133. 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())));
  134. MetaModel::Init_AddAttribute(new AttributeInteger("object_id", array("allowed_values"=>null, "sql"=>"object_id", "default_value"=>0, "is_null_allowed"=>false, "depends_on"=>array())));
  135. // Display lists
  136. MetaModel::Init_SetZListItems('details', array('date', 'message', 'userinfo', 'trigger_id', 'action_id', 'object_id')); // Attributes to be displayed for the complete details
  137. MetaModel::Init_SetZListItems('list', array('date', 'message')); // Attributes to be displayed for a list
  138. // Search criteria
  139. // MetaModel::Init_SetZListItems('standard_search', array('name')); // Criteria of the std search form
  140. // MetaModel::Init_SetZListItems('advanced_search', array('name')); // Criteria of the advanced search form
  141. }
  142. }
  143. class EventNotificationEmail extends EventNotification
  144. {
  145. public static function Init()
  146. {
  147. $aParams = array
  148. (
  149. "category" => "core/cmdb,view_in_gui",
  150. "key_type" => "autoincrement",
  151. "name_attcode" => "",
  152. "state_attcode" => "",
  153. "reconc_keys" => array(),
  154. "db_table" => "priv_event_email",
  155. "db_key_field" => "id",
  156. "db_finalclass_field" => "",
  157. "display_template" => "",
  158. "order_by_default" => array('date' => false)
  159. );
  160. MetaModel::Init_Params($aParams);
  161. MetaModel::Init_InheritAttributes();
  162. MetaModel::Init_AddAttribute(new AttributeText("to", array("allowed_values"=>null, "sql"=>"to", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array())));
  163. MetaModel::Init_AddAttribute(new AttributeText("cc", array("allowed_values"=>null, "sql"=>"cc", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array())));
  164. MetaModel::Init_AddAttribute(new AttributeText("bcc", array("allowed_values"=>null, "sql"=>"bcc", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array())));
  165. MetaModel::Init_AddAttribute(new AttributeText("from", array("allowed_values"=>null, "sql"=>"from", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array())));
  166. MetaModel::Init_AddAttribute(new AttributeText("subject", array("allowed_values"=>null, "sql"=>"subject", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array())));
  167. MetaModel::Init_AddAttribute(new AttributeHTML("body", array("allowed_values"=>null, "sql"=>"body", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array())));
  168. MetaModel::Init_AddAttribute(new AttributeTable("attachments", array("allowed_values"=>null, "sql"=>"attachments", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array())));
  169. // Display lists
  170. 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
  171. MetaModel::Init_SetZListItems('list', array('date', 'message', 'to', 'subject', 'attachments')); // Attributes to be displayed for a list
  172. // Search criteria
  173. // MetaModel::Init_SetZListItems('standard_search', array('name')); // Criteria of the std search form
  174. // MetaModel::Init_SetZListItems('advanced_search', array('name')); // Criteria of the advanced search form
  175. }
  176. }
  177. class EventIssue extends Event
  178. {
  179. public static function Init()
  180. {
  181. $aParams = array
  182. (
  183. "category" => "core/cmdb,view_in_gui",
  184. "key_type" => "autoincrement",
  185. "name_attcode" => "",
  186. "state_attcode" => "",
  187. "reconc_keys" => array(),
  188. "db_table" => "priv_event_issue",
  189. "db_key_field" => "id",
  190. "db_finalclass_field" => "",
  191. "display_template" => "",
  192. "order_by_default" => array('date' => false)
  193. );
  194. MetaModel::Init_Params($aParams);
  195. MetaModel::Init_InheritAttributes();
  196. MetaModel::Init_AddAttribute(new AttributeString("issue", array("allowed_values"=>null, "sql"=>"issue", "default_value"=>null, "is_null_allowed"=>false, "depends_on"=>array())));
  197. MetaModel::Init_AddAttribute(new AttributeString("impact", array("allowed_values"=>null, "sql"=>"impact", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array())));
  198. MetaModel::Init_AddAttribute(new AttributeString("page", array("allowed_values"=>null, "sql"=>"page", "default_value"=>null, "is_null_allowed"=>false, "depends_on"=>array())));
  199. MetaModel::Init_AddAttribute(new AttributePropertySet("arguments_post", array("allowed_values"=>null, "sql"=>"arguments_post", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array())));
  200. MetaModel::Init_AddAttribute(new AttributePropertySet("arguments_get", array("allowed_values"=>null, "sql"=>"arguments_get", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array())));
  201. MetaModel::Init_AddAttribute(new AttributeTable("callstack", array("allowed_values"=>null, "sql"=>"callstack", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array())));
  202. MetaModel::Init_AddAttribute(new AttributePropertySet("data", array("allowed_values"=>null, "sql"=>"data", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array())));
  203. // Display lists
  204. MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'issue', 'impact', 'page', 'arguments_post', 'arguments_get', 'callstack', 'data')); // Attributes to be displayed for the complete details
  205. MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'issue', 'impact')); // Attributes to be displayed for a list
  206. // Search criteria
  207. // MetaModel::Init_SetZListItems('standard_search', array('name')); // Criteria of the std search form
  208. // MetaModel::Init_SetZListItems('advanced_search', array('name')); // Criteria of the advanced search form
  209. }
  210. protected function OnInsert()
  211. {
  212. // Init page information: name, arguments
  213. //
  214. $this->Set('page', @$GLOBALS['_SERVER']['SCRIPT_NAME']);
  215. if (array_key_exists('_GET', $GLOBALS) && is_array($GLOBALS['_GET']))
  216. {
  217. $this->Set('arguments_get', $GLOBALS['_GET']);
  218. }
  219. else
  220. {
  221. $this->Set('arguments_get', array());
  222. }
  223. if (array_key_exists('_POST', $GLOBALS) && is_array($GLOBALS['_POST']))
  224. {
  225. $aPost = array();
  226. foreach($GLOBALS['_POST'] as $sKey => $sValue)
  227. {
  228. if (is_string($sValue))
  229. {
  230. if (strlen($sValue) < 256)
  231. {
  232. $aPost[$sKey] = $sValue;
  233. }
  234. else
  235. {
  236. $aPost[$sKey] = "!long string: ".strlen($sValue). " chars";
  237. }
  238. }
  239. else
  240. {
  241. // Not a string
  242. $aPost[$sKey] = (string) $sValue;
  243. }
  244. }
  245. $this->Set('arguments_post', $aPost);
  246. }
  247. else
  248. {
  249. $this->Set('arguments_post', array());
  250. }
  251. $sLength = strlen($this->Get('issue'));
  252. if ($sLength > 255)
  253. {
  254. $this->Set('issue', substr($this->Get('issue'), 0, 200)." -truncated ($sLength chars)");
  255. }
  256. $sLength = strlen($this->Get('impact'));
  257. if ($sLength > 255)
  258. {
  259. $this->Set('impact', substr($this->Get('impact'), 0, 200)." -truncated ($sLength chars)");
  260. }
  261. $sLength = strlen($this->Get('page'));
  262. if ($sLength > 255)
  263. {
  264. $this->Set('page', substr($this->Get('page'), 0, 200)." -truncated ($sLength chars)");
  265. }
  266. }
  267. }
  268. class EventWebService extends Event
  269. {
  270. public static function Init()
  271. {
  272. $aParams = array
  273. (
  274. "category" => "core/cmdb,view_in_gui",
  275. "key_type" => "autoincrement",
  276. "name_attcode" => "",
  277. "state_attcode" => "",
  278. "reconc_keys" => array(),
  279. "db_table" => "priv_event_webservice",
  280. "db_key_field" => "id",
  281. "db_finalclass_field" => "",
  282. "display_template" => "",
  283. "order_by_default" => array('date' => false)
  284. );
  285. MetaModel::Init_Params($aParams);
  286. MetaModel::Init_InheritAttributes();
  287. MetaModel::Init_AddAttribute(new AttributeString("verb", array("allowed_values"=>null, "sql"=>"verb", "default_value"=>null, "is_null_allowed"=>false, "depends_on"=>array())));
  288. //MetaModel::Init_AddAttribute(new AttributeStructure("arguments", array("allowed_values"=>null, "sql"=>"data", "default_value"=>null, "is_null_allowed"=>false, "depends_on"=>array())));
  289. MetaModel::Init_AddAttribute(new AttributeBoolean("result", array("allowed_values"=>null, "sql"=>"result", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array())));
  290. MetaModel::Init_AddAttribute(new AttributeText("log_info", array("allowed_values"=>null, "sql"=>"log_info", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array())));
  291. MetaModel::Init_AddAttribute(new AttributeText("log_warning", array("allowed_values"=>null, "sql"=>"log_warning", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array())));
  292. MetaModel::Init_AddAttribute(new AttributeText("log_error", array("allowed_values"=>null, "sql"=>"log_error", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array())));
  293. MetaModel::Init_AddAttribute(new AttributeText("data", array("allowed_values"=>null, "sql"=>"data", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array())));
  294. // Display lists
  295. MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'verb', 'result', 'log_info', 'log_warning', 'log_error', 'data')); // Attributes to be displayed for the complete details
  296. MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'verb', 'result')); // Attributes to be displayed for a list
  297. // Search criteria
  298. // MetaModel::Init_SetZListItems('standard_search', array('name')); // Criteria of the std search form
  299. // MetaModel::Init_SetZListItems('advanced_search', array('name')); // Criteria of the advanced search form
  300. }
  301. }
  302. class EventLoginUsage extends Event
  303. {
  304. public static function Init()
  305. {
  306. $aParams = array
  307. (
  308. "category" => "core/cmdb,view_in_gui",
  309. "key_type" => "autoincrement",
  310. "name_attcode" => "",
  311. "state_attcode" => "",
  312. "reconc_keys" => array(),
  313. "db_table" => "priv_event_loginusage",
  314. "db_key_field" => "id",
  315. "db_finalclass_field" => "",
  316. "order_by_default" => array('date' => false)
  317. );
  318. MetaModel::Init_Params($aParams);
  319. MetaModel::Init_InheritAttributes();
  320. 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_MANUAL, "depends_on"=>array())));
  321. $aZList = array('date', 'user_id');
  322. if (MetaModel::IsValidAttCode('Contact', 'name'))
  323. {
  324. 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())));
  325. $aZList[] = 'contact_name';
  326. }
  327. if (MetaModel::IsValidAttCode('Contact', 'email'))
  328. {
  329. 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())));
  330. $aZList[] = 'contact_email';
  331. }
  332. // Display lists
  333. MetaModel::Init_SetZListItems('details', array_merge($aZList, array('userinfo', 'message'))); // Attributes to be displayed for the complete details
  334. MetaModel::Init_SetZListItems('list', array_merge($aZList, array('userinfo'))); // Attributes to be displayed for a list
  335. // Search criteria
  336. MetaModel::Init_SetZListItems('standard_search', $aZList); // Criteria of the std search form
  337. // MetaModel::Init_SetZListItems('advanced_search', array('name')); // Criteria of the advanced search form
  338. }
  339. }
  340. ?>