PageRenderTime 46ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 1ms

/vTigerCRM/vtigercrm/pkg/vtiger/modules/WSAPP/modules/WSAPP/WSAPP.php

https://gitlab.com/hop23typhu/list-theme
PHP | 151 lines | 112 code | 22 blank | 17 comment | 20 complexity | 0f4aeaff1384225fbab1d5591bf23682 MD5 | raw file
  1. <?php
  2. /*+**********************************************************************************
  3. * The contents of this file are subject to the vtiger CRM Public License Version 1.1
  4. * ("License"); You may not use this file except in compliance with the License
  5. * The Original Code is: vtiger CRM Open Source
  6. * The Initial Developer of the Original Code is vtiger.
  7. * Portions created by vtiger are Copyright (C) vtiger.
  8. * All Rights Reserved.
  9. ************************************************************************************/
  10. require_once('include/events/include.inc');
  11. require_once 'modules/WSAPP/Utils.php';
  12. class WSAPP {
  13. /**
  14. * Invoked when special actions are performed on the module.
  15. * @param String Module name
  16. * @param String Event Type (module.postinstall, module.disabled, module.enabled, module.preuninstall)
  17. */
  18. function vtlib_handler($modulename, $event_type) {
  19. if($event_type == 'module.postinstall') {
  20. $this->initCustomWebserviceOperations();
  21. $this->registerHandlers();
  22. $this->registerVtigerCRMApp();
  23. $this->registerWsappWorkflowhandler();
  24. $this->registerSynclibEventHandler();
  25. } else if($event_type == 'module.disabled') {
  26. // TODO Handle actions when this module is disabled.
  27. return;
  28. } else if($event_type == 'module.enabled') {
  29. // TODO Handle actions when this module is enabled.
  30. return;
  31. } else if($event_type == 'module.preuninstall') {
  32. // TODO Handle actions when this module is about to be deleted.
  33. return;
  34. } else if($event_type == 'module.preupdate') {
  35. // TODO Handle actions before this module is updated.
  36. return;
  37. } else if($event_type == 'module.postupdate') {
  38. $this->registerSynclibEventHandler();
  39. }
  40. }
  41. function initCustomWebserviceOperations() {
  42. $operations = array();
  43. $wsapp_register_parameters = array('type' => 'string','synctype'=>'string');
  44. $operations['wsapp_register'] = array(
  45. 'file' => 'modules/WSAPP/api/ws/Register.php', 'handler' => 'wsapp_register', 'reqtype' => 'POST', 'prelogin' => '0',
  46. 'parameters' => $wsapp_register_parameters );
  47. $wsapp_deregister_parameters = array('type' => 'string', 'key' => 'string');
  48. $operations['wsapp_deregister'] = array(
  49. 'file' => 'modules/WSAPP/api/ws/DeRegister.php', 'handler' => 'wsapp_deregister', 'reqtype' => 'POST', 'prelogin' => '0',
  50. 'parameters' => $wsapp_deregister_parameters );
  51. $wsapp_get_parameters = array('key' => 'string', 'module' => 'string', 'token' => 'string');
  52. $operations['wsapp_get'] = array(
  53. 'file' => 'modules/WSAPP/api/ws/Get.php', 'handler' => 'wsapp_get', 'reqtype' => 'POST', 'prelogin' => '0',
  54. 'parameters' => $wsapp_get_parameters );
  55. $wsapp_put_parameters = array('key' => 'string', 'element' => 'encoded');
  56. $operations['wsapp_put'] = array(
  57. 'file' => 'modules/WSAPP/api/ws/Put.php', 'handler' => 'wsapp_put', 'reqtype' => 'POST', 'prelogin' => '0',
  58. 'parameters' => $wsapp_put_parameters );
  59. $wsapp_put_parameters = array('key' => 'string', 'element' => 'encoded');
  60. $operations['wsapp_map'] = array(
  61. 'file' => 'modules/WSAPP/api/ws/Map.php', 'handler' => 'wsapp_map', 'reqtype' => 'POST', 'prelogin' => '0',
  62. 'parameters' => $wsapp_put_parameters );
  63. $this->registerCustomWebservices( $operations );
  64. }
  65. function registerCustomWebservices( $operations ) {
  66. global $adb;
  67. foreach($operations as $operation_name => $operation_info) {
  68. $checkres = $adb->pquery("SELECT operationid FROM vtiger_ws_operation WHERE name=?", array($operation_name));
  69. if($checkres && $adb->num_rows($checkres) < 1) {
  70. $operation_id = $adb->getUniqueId('vtiger_ws_operation');
  71. $operation_res = $adb->pquery(
  72. "INSERT INTO vtiger_ws_operation (operationid, name, handler_path, handler_method, type, prelogin)
  73. VALUES (?,?,?,?,?,?)",
  74. array($operation_id, $operation_name, $operation_info['file'], $operation_info['handler'],
  75. $operation_info['reqtype'], $operation_info['prelogin'])
  76. );
  77. $operation_parameters = $operation_info['parameters'];
  78. $parameter_index = 0;
  79. foreach($operation_parameters as $parameter_name => $parameter_type) {
  80. $adb->pquery(
  81. "INSERT INTO vtiger_ws_operation_parameters (operationid, name, type, sequence)
  82. VALUES(?,?,?,?)", array($operation_id, $parameter_name, $parameter_type, ($parameter_index+1))
  83. );
  84. ++$parameter_index;
  85. }
  86. Vtiger_Utils::Log("Opearation $operation_name enabled successfully.");
  87. } else {
  88. Vtiger_Utils::Log("Operation $operation_name already exists.");
  89. }
  90. }
  91. }
  92. function registerHandlers(){
  93. global $adb;
  94. $handlerDetails = array();
  95. $appTypehandler = array();
  96. $appTypehandler['type'] = "Outlook";
  97. $appTypehandler['handlerclass'] = "OutlookHandler";
  98. $appTypehandler['handlerpath'] = "modules/WSAPP/Handlers/OutlookHandler.php";
  99. $handlerDetails[] = $appTypehandler;
  100. $appTypehandler = array();
  101. $appTypehandler['type'] = "vtigerCRM";
  102. $appTypehandler['handlerclass'] = "vtigerCRMHandler";
  103. $appTypehandler['handlerpath'] = "modules/WSAPP/Handlers/vtigerCRMHandler.php";
  104. $handlerDetails[] = $appTypehandler;
  105. foreach($handlerDetails as $appHandlerDetails)
  106. $adb->pquery("INSERT INTO vtiger_wsapp_handlerdetails VALUES(?,?,?)",array($appHandlerDetails['type'],$appHandlerDetails['handlerclass'],$appHandlerDetails['handlerpath']));
  107. }
  108. function registerVtigerCRMApp(){
  109. $db = PearDatabase::getInstance();
  110. $appName = "vtigerCRM";
  111. $type ="user";
  112. $uid = uniqid();
  113. $db->pquery("INSERT INTO vtiger_wsapp (name, appkey,type) VALUES(?,?,?)", array($appName, $uid,$type));
  114. }
  115. function registerWsappWorkflowhandler(){
  116. $db = PearDatabase::getInstance();
  117. $em = new VTEventsManager($db);
  118. $dependentEventHandlers = array('VTEntityDelta');
  119. $dependentEventHandlersJson = Zend_Json::encode($dependentEventHandlers);
  120. $em->registerHandler('vtiger.entity.aftersave', 'modules/WSAPP/WorkFlowHandlers/WSAPPAssignToTracker.php', 'WSAPPAssignToTracker','',$dependentEventHandlersJson);
  121. }
  122. function registerSynclibEventHandler(){
  123. $className='WSAPP_VtigerSyncEventHandler';
  124. $path = 'modules/WSAPP/synclib/handlers/VtigerSyncEventHandler.php';
  125. $type = 'vtigerSyncLib';
  126. wsapp_RegisterHandler($type, $className, $path);
  127. }
  128. }
  129. ?>