event.class.inc.php 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  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. );
  42. MetaModel::Init_Params($aParams);
  43. //MetaModel::Init_InheritAttributes();
  44. MetaModel::Init_AddAttribute(new AttributeText("message", array("allowed_values"=>null, "sql"=>"message", "default_value"=>null, "is_null_allowed"=>false, "depends_on"=>array())));
  45. MetaModel::Init_AddAttribute(new AttributeDateTime("date", array("allowed_values"=>null, "sql"=>"date", "default_value"=>"", "is_null_allowed"=>false, "depends_on"=>array())));
  46. MetaModel::Init_AddAttribute(new AttributeString("userinfo", array("allowed_values"=>null, "sql"=>"userinfo", "default_value"=>null, "is_null_allowed"=>true, "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. // Display lists
  49. MetaModel::Init_SetZListItems('details', array('date', 'message', 'userinfo')); // Attributes to be displayed for the complete details
  50. MetaModel::Init_SetZListItems('list', array('date', 'finalclass', 'message')); // Attributes to be displayed for a list
  51. // Search criteria
  52. // MetaModel::Init_SetZListItems('standard_search', array('name')); // Criteria of the std search form
  53. // MetaModel::Init_SetZListItems('advanced_search', array('name')); // Criteria of the advanced search form
  54. }
  55. /**
  56. * Maps the given context parameter name to the appropriate filter/search code for this class
  57. * @param string $sContextParam Name of the context parameter, i.e. 'org_id'
  58. * @return string Filter code, i.e. 'customer_id'
  59. */
  60. public static function MapContextParam($sContextParam)
  61. {
  62. if ($sContextParam == 'menu')
  63. {
  64. return null;
  65. }
  66. else
  67. {
  68. return $sContextParam;
  69. }
  70. }
  71. /**
  72. * This function returns a 'hilight' CSS class, used to hilight a given row in a table
  73. * There are currently (i.e defined in the CSS) 4 possible values HILIGHT_CLASS_CRITICAL,
  74. * HILIGHT_CLASS_WARNING, HILIGHT_CLASS_OK, HILIGHT_CLASS_NONE
  75. * To Be overridden by derived classes
  76. * @param void
  77. * @return String The desired higlight class for the object/row
  78. */
  79. public function GetHilightClass()
  80. {
  81. // Possible return values are:
  82. // HILIGHT_CLASS_CRITICAL, HILIGHT_CLASS_WARNING, HILIGHT_CLASS_OK, HILIGHT_CLASS_NONE
  83. return HILIGHT_CLASS_NONE; // Not hilighted by default
  84. }
  85. public static function GetUIPage()
  86. {
  87. return 'UI.php';
  88. }
  89. function DisplayDetails(WebPage $oPage, $bEditMode = false)
  90. {
  91. // Object's details
  92. //$this->DisplayBareHeader($oPage, $bEditMode);
  93. $oPage->AddTabContainer(OBJECT_PROPERTIES_TAB);
  94. $oPage->SetCurrentTabContainer(OBJECT_PROPERTIES_TAB);
  95. $oPage->SetCurrentTab(Dict::S('UI:PropertiesTab'));
  96. $this->DisplayBareProperties($oPage, $bEditMode);
  97. }
  98. function DisplayBareProperties(WebPage $oPage, $bEditMode = false, $sPrefix = '', $aExtraParams = array())
  99. {
  100. if ($bEditMode) return; // Not editable
  101. $aDetails = array();
  102. $sClass = get_class($this);
  103. $aZList = MetaModel::FlattenZlist(MetaModel::GetZListItems($sClass, 'details'));
  104. foreach( $aZList as $sAttCode)
  105. {
  106. $sDisplayValue = $this->GetAsHTML($sAttCode);
  107. $aDetails[] = array('label' => '<span title="'.MetaModel::GetDescription($sClass, $sAttCode).'">'.MetaModel::GetLabel($sClass, $sAttCode).'</span>', 'value' => $sDisplayValue);
  108. }
  109. $oPage->Details($aDetails);
  110. }
  111. }
  112. class EventNotification extends Event
  113. {
  114. public static function Init()
  115. {
  116. $aParams = array
  117. (
  118. "category" => "core/cmdb,view_in_gui",
  119. "key_type" => "autoincrement",
  120. "name_attcode" => "",
  121. "state_attcode" => "",
  122. "reconc_keys" => array(),
  123. "db_table" => "priv_event_notification",
  124. "db_key_field" => "id",
  125. "db_finalclass_field" => "",
  126. "display_template" => "",
  127. );
  128. MetaModel::Init_Params($aParams);
  129. MetaModel::Init_InheritAttributes();
  130. 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())));
  131. 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())));
  132. MetaModel::Init_AddAttribute(new AttributeInteger("object_id", array("allowed_values"=>null, "sql"=>"object_id", "default_value"=>0, "is_null_allowed"=>false, "depends_on"=>array())));
  133. // Display lists
  134. MetaModel::Init_SetZListItems('details', array('date', 'message', 'userinfo', 'trigger_id', 'action_id', 'object_id')); // Attributes to be displayed for the complete details
  135. MetaModel::Init_SetZListItems('list', array('date', 'message')); // Attributes to be displayed for a list
  136. // Search criteria
  137. // MetaModel::Init_SetZListItems('standard_search', array('name')); // Criteria of the std search form
  138. // MetaModel::Init_SetZListItems('advanced_search', array('name')); // Criteria of the advanced search form
  139. }
  140. }
  141. class EventNotificationEmail extends EventNotification
  142. {
  143. public static function Init()
  144. {
  145. $aParams = array
  146. (
  147. "category" => "core/cmdb,view_in_gui",
  148. "key_type" => "autoincrement",
  149. "name_attcode" => "",
  150. "state_attcode" => "",
  151. "reconc_keys" => array(),
  152. "db_table" => "priv_event_email",
  153. "db_key_field" => "id",
  154. "db_finalclass_field" => "",
  155. "display_template" => "",
  156. );
  157. MetaModel::Init_Params($aParams);
  158. MetaModel::Init_InheritAttributes();
  159. MetaModel::Init_AddAttribute(new AttributeText("to", array("allowed_values"=>null, "sql"=>"to", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array())));
  160. MetaModel::Init_AddAttribute(new AttributeText("cc", array("allowed_values"=>null, "sql"=>"cc", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array())));
  161. MetaModel::Init_AddAttribute(new AttributeText("bcc", array("allowed_values"=>null, "sql"=>"bcc", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array())));
  162. MetaModel::Init_AddAttribute(new AttributeText("from", array("allowed_values"=>null, "sql"=>"from", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array())));
  163. MetaModel::Init_AddAttribute(new AttributeText("subject", array("allowed_values"=>null, "sql"=>"subject", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array())));
  164. MetaModel::Init_AddAttribute(new AttributeHTML("body", array("allowed_values"=>null, "sql"=>"body", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array())));
  165. MetaModel::Init_AddAttribute(new AttributeTable("attachments", array("allowed_values"=>null, "sql"=>"attachments", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array())));
  166. // Display lists
  167. 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
  168. MetaModel::Init_SetZListItems('list', array('date', 'message', 'to', 'subject', 'attachments')); // Attributes to be displayed for a list
  169. // Search criteria
  170. // MetaModel::Init_SetZListItems('standard_search', array('name')); // Criteria of the std search form
  171. // MetaModel::Init_SetZListItems('advanced_search', array('name')); // Criteria of the advanced search form
  172. }
  173. }
  174. class EventIssue extends Event
  175. {
  176. public static function Init()
  177. {
  178. $aParams = array
  179. (
  180. "category" => "core/cmdb,view_in_gui",
  181. "key_type" => "autoincrement",
  182. "name_attcode" => "",
  183. "state_attcode" => "",
  184. "reconc_keys" => array(),
  185. "db_table" => "priv_event_issue",
  186. "db_key_field" => "id",
  187. "db_finalclass_field" => "",
  188. "display_template" => "",
  189. );
  190. MetaModel::Init_Params($aParams);
  191. MetaModel::Init_InheritAttributes();
  192. MetaModel::Init_AddAttribute(new AttributeString("issue", array("allowed_values"=>null, "sql"=>"issue", "default_value"=>null, "is_null_allowed"=>false, "depends_on"=>array())));
  193. MetaModel::Init_AddAttribute(new AttributeString("impact", array("allowed_values"=>null, "sql"=>"impact", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array())));
  194. MetaModel::Init_AddAttribute(new AttributeString("page", array("allowed_values"=>null, "sql"=>"page", "default_value"=>null, "is_null_allowed"=>false, "depends_on"=>array())));
  195. MetaModel::Init_AddAttribute(new AttributePropertySet("arguments_post", array("allowed_values"=>null, "sql"=>"arguments_post", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array())));
  196. MetaModel::Init_AddAttribute(new AttributePropertySet("arguments_get", array("allowed_values"=>null, "sql"=>"arguments_get", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array())));
  197. MetaModel::Init_AddAttribute(new AttributeTable("callstack", array("allowed_values"=>null, "sql"=>"callstack", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array())));
  198. MetaModel::Init_AddAttribute(new AttributePropertySet("data", array("allowed_values"=>null, "sql"=>"data", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array())));
  199. // Display lists
  200. MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'issue', 'impact', 'page', 'arguments_post', 'arguments_get', 'callstack', 'data')); // Attributes to be displayed for the complete details
  201. MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'issue', 'impact')); // Attributes to be displayed for a list
  202. // Search criteria
  203. // MetaModel::Init_SetZListItems('standard_search', array('name')); // Criteria of the std search form
  204. // MetaModel::Init_SetZListItems('advanced_search', array('name')); // Criteria of the advanced search form
  205. }
  206. protected function OnInsert()
  207. {
  208. // Init page information: name, arguments
  209. //
  210. $this->Set('page', @$GLOBALS['_SERVER']['SCRIPT_NAME']);
  211. if (array_key_exists('_GET', $GLOBALS) && is_array($GLOBALS['_GET']))
  212. {
  213. $this->Set('arguments_get', $GLOBALS['_GET']);
  214. }
  215. else
  216. {
  217. $this->Set('arguments_get', array());
  218. }
  219. if (array_key_exists('_POST', $GLOBALS) && is_array($GLOBALS['_POST']))
  220. {
  221. $aPost = array();
  222. foreach($GLOBALS['_POST'] as $sKey => $sValue)
  223. {
  224. if (is_string($sValue))
  225. {
  226. if (strlen($sValue) < 256)
  227. {
  228. $aPost[$sKey] = $sValue;
  229. }
  230. else
  231. {
  232. $aPost[$sKey] = "!long string: ".strlen($sValue). " chars";
  233. }
  234. }
  235. else
  236. {
  237. // Not a string
  238. $aPost[$sKey] = (string) $sValue;
  239. }
  240. }
  241. $this->Set('arguments_post', $aPost);
  242. }
  243. else
  244. {
  245. $this->Set('arguments_post', array());
  246. }
  247. $sLength = strlen($this->Get('issue'));
  248. if ($sLength > 255)
  249. {
  250. $this->Set('issue', substr($this->Get('issue'), 0, 200)." -truncated ($sLength chars)");
  251. }
  252. $sLength = strlen($this->Get('impact'));
  253. if ($sLength > 255)
  254. {
  255. $this->Set('impact', substr($this->Get('impact'), 0, 200)." -truncated ($sLength chars)");
  256. }
  257. $sLength = strlen($this->Get('page'));
  258. if ($sLength > 255)
  259. {
  260. $this->Set('page', substr($this->Get('page'), 0, 200)." -truncated ($sLength chars)");
  261. }
  262. }
  263. }
  264. class EventWebService extends Event
  265. {
  266. public static function Init()
  267. {
  268. $aParams = array
  269. (
  270. "category" => "core/cmdb,view_in_gui",
  271. "key_type" => "autoincrement",
  272. "name_attcode" => "",
  273. "state_attcode" => "",
  274. "reconc_keys" => array(),
  275. "db_table" => "priv_event_webservice",
  276. "db_key_field" => "id",
  277. "db_finalclass_field" => "",
  278. "display_template" => "",
  279. );
  280. MetaModel::Init_Params($aParams);
  281. MetaModel::Init_InheritAttributes();
  282. MetaModel::Init_AddAttribute(new AttributeString("verb", array("allowed_values"=>null, "sql"=>"verb", "default_value"=>null, "is_null_allowed"=>false, "depends_on"=>array())));
  283. //MetaModel::Init_AddAttribute(new AttributeStructure("arguments", array("allowed_values"=>null, "sql"=>"data", "default_value"=>null, "is_null_allowed"=>false, "depends_on"=>array())));
  284. MetaModel::Init_AddAttribute(new AttributeBoolean("result", array("allowed_values"=>null, "sql"=>"result", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array())));
  285. MetaModel::Init_AddAttribute(new AttributeText("log_info", array("allowed_values"=>null, "sql"=>"log_info", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array())));
  286. MetaModel::Init_AddAttribute(new AttributeText("log_warning", array("allowed_values"=>null, "sql"=>"log_warning", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array())));
  287. MetaModel::Init_AddAttribute(new AttributeText("log_error", array("allowed_values"=>null, "sql"=>"log_error", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array())));
  288. MetaModel::Init_AddAttribute(new AttributeText("data", array("allowed_values"=>null, "sql"=>"data", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array())));
  289. // Display lists
  290. MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'verb', 'result', 'log_info', 'log_warning', 'log_error', 'data')); // Attributes to be displayed for the complete details
  291. MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'verb', 'result')); // Attributes to be displayed for a list
  292. // Search criteria
  293. // MetaModel::Init_SetZListItems('standard_search', array('name')); // Criteria of the std search form
  294. // MetaModel::Init_SetZListItems('advanced_search', array('name')); // Criteria of the advanced search form
  295. }
  296. }
  297. class EventLoginUsage extends Event
  298. {
  299. public static function Init()
  300. {
  301. $aParams = array
  302. (
  303. "category" => "core/cmdb,view_in_gui",
  304. "key_type" => "autoincrement",
  305. "name_attcode" => "",
  306. "state_attcode" => "",
  307. "reconc_keys" => array(),
  308. "db_table" => "priv_event_loginusage",
  309. "db_key_field" => "id",
  310. "db_finalclass_field" => "",
  311. );
  312. MetaModel::Init_Params($aParams);
  313. MetaModel::Init_InheritAttributes();
  314. 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())));
  315. $aZList = array('date', 'user_id');
  316. if (MetaModel::IsValidAttCode('Contact', 'name'))
  317. {
  318. 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())));
  319. $aZList[] = 'contact_name';
  320. }
  321. if (MetaModel::IsValidAttCode('Contact', 'email'))
  322. {
  323. 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())));
  324. $aZList[] = 'contact_email';
  325. }
  326. // Display lists
  327. MetaModel::Init_SetZListItems('details', array_merge($aZList, array('userinfo', 'message'))); // Attributes to be displayed for the complete details
  328. MetaModel::Init_SetZListItems('list', array_merge($aZList, array('userinfo'))); // Attributes to be displayed for a list
  329. // Search criteria
  330. MetaModel::Init_SetZListItems('standard_search', $aZList); // Criteria of the std search form
  331. // MetaModel::Init_SetZListItems('advanced_search', array('name')); // Criteria of the advanced search form
  332. }
  333. }
  334. ?>