PageRenderTime 40ms CodeModel.GetById 12ms RepoModel.GetById 1ms app.codeStats 0ms

/apps/bpm/controllers/requests.php

https://github.com/jplante815/meican
PHP | 244 lines | 145 code | 30 blank | 69 comment | 13 complexity | 38a728385eaccb7d4cfeb996f2e738c7 MD5 | raw file
  1. <?php
  2. include_once 'libs/meican_controller.php';
  3. include_once 'libs/auth.php';
  4. include_once 'apps/bpm/models/request_info.php';
  5. include_once 'apps/circuits/models/reservation_info.php';
  6. include_once 'apps/circuits/models/gri_info.php';
  7. include_once 'apps/aaa/models/user_info.php';
  8. include_once 'apps/topology/models/domain_info.php';
  9. include_once 'libs/nuSOAP/lib/nusoap.php';
  10. class requests extends MeicanController {
  11. public $modelClass = 'request_info';
  12. public function requests() {
  13. $this->app = 'bpm';
  14. $this->controller = 'requests';
  15. $this->defaultAction = 'show';
  16. }
  17. protected function renderEmpty() {
  18. $this->set(array(
  19. 'title' => _("Requests"),
  20. 'message' => _("You have no pending or finished request"),
  21. 'link' => false
  22. ));
  23. parent::renderEmpty();
  24. }
  25. public function show() {
  26. if ($requests = $this->makeIndex(array('answerable' => 'yes'))) {
  27. $pending = array();
  28. $finished = array();
  29. foreach ($requests as $req) {
  30. if (!$req->response)
  31. $pending[] = $req->getRequestInfo(TRUE);
  32. else
  33. $finished[] = $req->getRequestInfo(TRUE);
  34. }
  35. $this->set(compact('pending', 'finished'));
  36. }
  37. $this->render('show');
  38. }
  39. // public function createRequest () {
  40. //
  41. // $domain = new domain_info();
  42. // $domains = $domain->fetch(FALSE);
  43. //
  44. // $this->setArgsToBody($domains);
  45. // $this->addScript('bpmStrategy');
  46. // $this->render('createRequest');
  47. // }
  48. //
  49. // public function getUsers() {
  50. //
  51. // $dom_ip = $_POST['dom_ip'];
  52. //
  53. // //consulta domínio remoto via web service para buscar os usuários do mesmo
  54. // $client = new nusoap_client("http://$dom_ip/".Configure::read('systemDirName')."bpm/ws", array('cache_wsdl' => 0));
  55. //
  56. // $result = $client->call('getUsers');
  57. // $this->renderJson($result);
  58. // }
  59. public function reply($input) {
  60. $locId = NULL;
  61. if (array_key_exists('loc_id', $input)) {
  62. $locId = $input['loc_id'];
  63. } else {
  64. $this->setFlash(_("Invalid index"), "fatal");
  65. $this->show();
  66. return;
  67. }
  68. $request = new request_info();
  69. $request->loc_id = $input['loc_id'];
  70. $req_result = $request->fetch();
  71. $result = $req_result[0]->getRequestInfo(TRUE, TRUE, TRUE, TRUE);
  72. $gri = new gri_info();
  73. $offset = (30 * 24 * 60 * 60);
  74. $calendar_gris = gri_info::getGrisToCalendar(date('Y-m-d H:i:s', time() - $offset), date('Y-m-d H:i:s', time() + $offset), $result->resc_id);
  75. //Log::write("debug", print_r($gri->getGrisToView($result->resc_id, true), true));
  76. $this->set(array(
  77. 'res_id' => $result->resc_id,
  78. 'res_name' => $result->resc_descr,
  79. 'bandwidth' => $result->bandwidth,
  80. 'usr_login' => $result->src_user,
  81. 'timer' => $result->timer_info,
  82. 'flow' => $result->flow_info,
  83. 'gris' => $gri->getGrisToView($result->resc_id, true),
  84. 'calendar_gris' => $calendar_gris ? $calendar_gris : array(),
  85. 'request' => $result,
  86. 'refresh' => 0
  87. ));
  88. $this->setArgsToScript(array(
  89. "src_lat_network" => $result->flow_info->source->latitude,
  90. "src_lng_network" => $result->flow_info->source->longitude,
  91. "dst_lat_network" => $result->flow_info->dest->latitude,
  92. "dst_lng_network" => $result->flow_info->dest->longitude,
  93. 'refreshReservation' => 0,
  94. 'reservation_path' => $result->flow_info->path,
  95. // string messages
  96. 'ok_string' => _("Ok"),
  97. 'cancel_string' => _("Cancel"),
  98. 'accept_message' => _("Request will be accepted, please provide a message"),
  99. 'reject_message' => _("Request will be rejected, please provide a message"),
  100. 'available_bandwidth_string' => _("Available bandwidth"),
  101. 'requested_bandwidth_string' => _("Requested bandwidth")
  102. ));
  103. $this->addScriptForLayout('requests');
  104. $this->render('reply2');
  105. }
  106. public function saveResponse($request) {
  107. $locId = NULL;
  108. if (array_key_exists('loc_id', $request)) {
  109. $locId = $request['loc_id'];
  110. } else {
  111. $this->setFlash(_("Invalid index"), "fatal");
  112. $this->show();
  113. return;
  114. }
  115. //insere no banco local
  116. $to_response = new request_info();
  117. $to_response->loc_id = $locId;
  118. $to_response->answerable = 'yes';
  119. $to_response->response = Common::POST('response');
  120. $to_response->message = Common::POST('message');
  121. if ($to_response->response()) {
  122. $this->setFlash(_('Response saved'), "success");
  123. $this->show();
  124. return;
  125. } else {
  126. $this->setFlash(_('Response NOT saved'), "error");
  127. $this->show();
  128. return;
  129. }
  130. }
  131. /**
  132. * @todo pensar em como apagar se request for de outro domínio
  133. *
  134. * Atualmente apagando tudo! Modificar posteriormente!
  135. */
  136. public function delete() {
  137. if ($requests = Common::POST("del_checkbox")) {
  138. $count = 0;
  139. foreach ($requests as $loc_id) {
  140. $request = new request_info();
  141. $request->loc_id = $loc_id;
  142. $req_result = $request->fetch(FALSE);
  143. $del_request = new request_info();
  144. $del_request->req_id = $req_result[0]->req_id;
  145. $del_request->src_ode_ip = $req_result[0]->src_ode_ip;
  146. if ($requests_to_delete = $del_request->fetch(false)) {
  147. $were_deleted = TRUE;
  148. foreach ($requests_to_delete as $r_del) {
  149. $req = new request_info();
  150. $req->loc_id = $r_del->loc_id;
  151. $were_deleted &= $req->delete(false);
  152. }
  153. if (($were_deleted) && ($r_del->answerable = 'yes'))
  154. $count++;
  155. }
  156. }
  157. switch ($count) {
  158. case 0:
  159. $this->setFlash(_("No request was deleted"), 'warning');
  160. break;
  161. case 1:
  162. $this->setFlash(_("One request was deleted"), 'success');
  163. break;
  164. default:
  165. $this->setFlash("$count " . _("requests were deleted"),
  166. 'success');
  167. break;
  168. }
  169. }
  170. $this->show();
  171. }
  172. // function notifyResponse($response) {
  173. // debug('acionando notify response', $response);
  174. //
  175. // if ($response) {
  176. //
  177. // $req = new request_info();
  178. // $req->req_id = $response['req_id'];
  179. // $req->setDom('dom_src', $response['dom_src_ip']);
  180. // $req->answerable = 'no';
  181. //
  182. // if ($result = $req->updateTo(array('message' => $response['message'], 'response' => $response['response']), FALSE)) {
  183. // if ($response['response'] == 'accept') {
  184. //
  185. // if ($req->updateTo(array('status' => 'SENT TO OSCARS'), FALSE)){
  186. // //requisicao aceita deve enviar ao OSCARS
  187. // debug('enviando ao OSCARS...');
  188. // $reservation = $req->fetch(FALSE);
  189. // $res = new oscars($reservation[0]->resource_id);
  190. // if ($res->createReservation())
  191. // return TRUE;
  192. // else {
  193. // debug('erro ao enviar ao oscars');
  194. // return NULL;
  195. // }
  196. // }
  197. // } else {
  198. // //requisicao negada, termina
  199. // debug('requisicao negada', $response['req_id']);
  200. // return TRUE;
  201. // }
  202. // } else {
  203. // //requisicao nao encontrada no banco local, requisicao nao enviada a este dominio
  204. // debug('req nao encontrada', $response['req_id']);
  205. // return NULL;
  206. // }
  207. // } else {
  208. // debug('notifyresponse without response set');
  209. // return NULL;
  210. // }
  211. // }
  212. }
  213. //class requests
  214. ?>