public function executeJson(sfWebRequest $request) { $etva_service = EtvaServicePeer::retrieveByPK($request->getParameter('id')); if (!$etva_service) { $msg = array('success' => false, 'error' => 'No service with specified id', 'info' => 'No service with specified id'); $result = $this->setJsonError($msg); $this->getResponse()->setHttpHeader('Content-type', 'application/json'); return $this->renderText($result); } $etva_server = $etva_service->getEtvaServer(); $agent_tmpl = $etva_server->getAgentTmpl(); $service_tmpl = $etva_service->getNameTmpl(); $method = $request->getParameter('method'); $mode = $request->getParameter('mode'); $params = json_decode($request->getParameter('params'), true); if (!$params) { $params = array(); } $dispatcher_tmpl = $agent_tmpl . '_' . $service_tmpl; if (method_exists($this, $dispatcher_tmpl)) { $ret = call_user_func_array(array($this, $dispatcher_tmpl), array($etva_server, $method, $params, $mode)); if ($ret['success']) { $result = json_encode($ret); } else { $result = $this->setJsonError($ret); } } else { $info = array('success' => false, 'error' => 'No method implemented! ' . $dispatcher_tmpl); $result = $this->setJsonError($info); } // $result = json_encode($ret); $this->getResponse()->setHttpHeader('Content-type', 'application/json; charset=utf-8'); $this->getResponse()->setHttpHeader("X-JSON", '()'); return $this->renderText($result); }
public function executeJsonGetServer(sfWebRequest $request) { $etva_service = EtvaServicePeer::retrieveByPK($request->getParameter('id')); if (!$etva_service) { $msg = array('success' => false, 'error' => 'No service with specified id', 'info' => 'No service with specified id'); $result = $this->setJsonError($msg); return $this->renderText($result); } $etva_server = $etva_service->getEtvaServer(); $server_array = $etva_server->toArray(BasePeer::TYPE_FIELDNAME); $result = array('success' => true, 'data' => $server_array); $this->getResponse()->setHttpHeader('Content-type', 'application/json'); $return = json_encode($result); return $this->renderText($return); }
/** * Executes index action * * @param sfRequest $request A request object */ public function executeView(sfWebRequest $request) { $dispatcher_id = $request->getParameter('dispatcher_id'); // load modules file of dispatcher if ($dispatcher_id) { $criteria = new Criteria(); $criteria->add(EtvaServicePeer::ID, $dispatcher_id); $etva_service = EtvaServicePeer::doSelectOne($criteria); $dispatcher = $etva_service->getNameTmpl(); $etva_server = $etva_service->getEtvaServer(); $tmpl = $etva_server->getAgentTmpl() . '_' . $dispatcher . '_modules'; //if exists, load _DUMMY_main_modules.php file $directory = $this->context->getConfiguration()->getTemplateDir('dummy', '_' . $tmpl . '.php'); if ($directory) { return $this->renderPartial($tmpl); } else { return $this->renderText('Template ' . $tmpl . ' not found'); } } else { $this->etva_server = EtvaServerPeer::retrieveByPK($request->getParameter('sid')); } }
public function executeJsonUpdateUserService(sfWebRequest $request) { $isAjax = $request->isXmlHttpRequest(); if (!$isAjax) { return $this->redirect('@homepage'); } $id = $request->getParameter('id'); if (!($sf_user = sfGuardUserPeer::retrieveByPK($id))) { $msg_i18n = $this->getContext()->getI18N()->__(sfGuardUserPeer::_ERR_NOTFOUND_ID_, array('%id%' => $id)); $error = array('success' => false, 'agent' => sfConfig::get('config_acronym'), 'error' => $msg_i18n, 'info' => $msg_i18n); // if is browser request return text renderer $error = $this->setJsonError($error); return $this->renderText($error); } $service_id = $request->getParameter('service_id'); //$this->forward404Unless($etva_service = EtvaServicePeer::retrieveByPk($service_id), sprintf('Object etva_service does not exist (%s).', $service_id)); if (!EtvaServicePeer::retrieveByPk($service_id)) { $msg_i18n = $this->getContext()->getI18N()->__('Object etva_service does not exist (%service_id%).', array('%service_id%' => $service_id)); $error = array('success' => false, 'agent' => sfConfig::get('config_acronym'), 'error' => $msg_i18n, 'info' => $msg_i18n); // if is browser request return text renderer $error = $this->setJsonError($error); return $this->renderText($error); } $etva_user_service = EtvaUserServicePeer::retrieveByPK($id, $service_id); if (!$etva_user_service) { $etva_user_service = new EtvaUserService(); $etva_user_service->setUserId($id); $etva_user_service->setServiceId($service_id); } $extra = $request->getParameter('extra'); $etva_user_service->setExtra($extra); $etva_user_service->save(); $msg_i18n = $this->getContext()->getI18N()->__('User and service saved successfully'); $response = array('success' => true, 'agent' => 'Central Management', 'response' => $msg_i18n, 'user_id' => $id, 'service_id' => $service_id); $return = json_encode($response); $this->getResponse()->setHttpHeader('Content-type', 'application/json'); return $this->renderText($return); }
public function executeJsonNoWait(sfWebRequest $request) { $service_id = $request->getParameter('id'); $etva_service = EtvaServicePeer::retrieveByPK($request->getParameter('id')); if (!$etva_service) { $msg_i18n = $this->getContext()->getI18N()->__('No service with specified id', array()); $msg = array('success' => false, 'error' => $msg_i18n, 'info' => $msg_i18n); $result = $this->setJsonError($msg); $this->getResponse()->setHttpHeader('Content-type', 'application/json'); return $this->renderText($result); } $etva_server = $etva_service->getEtvaServer(); $method = $request->getParameter('method'); $params = json_decode($request->getParameter('params'), true); if (!$params) { $params = array(); } $etva_server->setSoapTimeout(5); // send soap request $response = $etva_server->soapSend($method, $params); if (!$response['success'] && $response['faultactor'] != 'socket_read') { $result = json_decode($response); } else { $msg_i18n = $this->getContext()->getI18N()->__('Change IP ok.', array()); $res = array('success' => true, 'agent' => $response['agent'], 'response' => $msg_i18n); $result = json_decode($res); } $this->getResponse()->setHttpHeader('Content-type', 'application/json; charset=utf-8'); $this->getResponse()->setHttpHeader("X-JSON", '()'); return $this->renderText($result); }
public function executeJsonGetServices(sfWebRequest $request) { $sid = $request->getParameter('sid'); $criteria = new Criteria(); $criteria->add(EtvaServicePeer::SERVER_ID, $sid); $etva_services = EtvaServicePeer::doSelect($criteria); $elements = array(); $i = 0; foreach ($etva_services as $item) { $item_arr = $item->toArray(BasePeer::TYPE_FIELDNAME); if (isset($item_arr['params'])) { // decode params $params = json_decode($item_arr['params'], true); $item_arr['params'] = $params; } $elements[$i] = $item_arr; $i++; } $data = array('total' => count($elements), 'data' => $elements); $result = json_encode($data); $this->getResponse()->setHttpHeader('Content-type', 'application/json'); return $this->renderText($result); }
public function deleteServices() { $c = new Criteria(); $c->add(EtvaServicePeer::SERVER_ID, $this->getId()); EtvaServicePeer::doDelete($c); }