setCookie() public méthode

Add a cookie to the request. If the client has no Cookie Jar, the cookies will be added directly to the headers array as "Cookie" headers.
public setCookie ( Zend_Http_Cookie | string $cookie, string | null $value = null ) : Zend_Http_Client
$cookie Zend_Http_Cookie | string
$value string | null If "cookie" is a string, this is the cookie value.
Résultat Zend_Http_Client
 public function logoutAction()
 {
     $serverUrl = 'http://' . AUTH_SERVER . self::AUTH_PATH . '/logout';
     $client = new Zend_Http_Client($serverUrl, array('timeout' => 30));
     try {
         if (isset($_COOKIE[self::AUTH_SID])) {
             $moduleName = $this->getRequest()->getModuleName();
             $client->setCookie('PHPSESSID', $_COOKIE[self::AUTH_SID]);
             $client->setCookie('moduleName', $moduleName);
             $response = $client->request();
             if ($response->isError()) {
                 $remoteErr = $response->getStatus() . ' : ' . $response->getMessage() . '<br/>' . $response->getBody();
                 throw new Zend_Exception($remoteErr, Zend_Log::ERR);
             }
         } else {
             $this->_helper->logger('No remote cookie found');
         }
     } catch (Zend_Exception $e) {
         echo $e->getMessage();
     }
     if (isset($_COOKIE[self::AUTH_SID])) {
         preg_match('/[^.]+\\.[^.]+$/', $_SERVER['SERVER_NAME'], $domain);
         setcookie(self::AUTH_SID, '', time() - 360000, self::AUTH_PATH, ".{$domain['0']}");
     }
     Zend_Auth::getInstance()->clearIdentity();
     Zend_Session::destroy();
 }
 public function logoutAction()
 {
     $this->_helper->layout()->disableLayout();
     $serverUrl = 'http://' . AUTH_SERVER . self::AUTH_PATH . '/logout';
     $client = new Zend_Http_Client($serverUrl, array('timeout' => 30));
     try {
         if (isset($_COOKIE[self::AUTH_SID])) {
             $moduleName = $this->getRequest()->getModuleName();
             $client->setCookie('PHPSESSID', $_COOKIE[self::AUTH_SID]);
             $client->setCookie('moduleName', $moduleName);
             $response = $client->request();
             if ($response->isError()) {
                 $remoteErr = $remoteErr = 'REMOTE ERROR: (' . $response->getStatus() . ') ' . $response->getMessage() . ', i.e. ' . $response->getHeader('Message');
                 throw new Zend_Exception($remoteErr, Zend_Log::ERR);
             }
         } else {
             $this->_helper->logger('No remote cookie found. So, not requesting AUTH_SERVER to logout.');
         }
     } catch (Zend_Exception $e) {
         echo $e->getMessage();
     }
     preg_match('/[^.]+\\.[^.]+$/', $_SERVER['SERVER_NAME'], $domain);
     if (isset($_COOKIE[self::AUTH_SID])) {
         setcookie(self::AUTH_SID, '', time() - 360000, self::AUTH_PATH, ".{$domain['0']}");
     }
     if (isset($_COOKIE['last'])) {
         setcookie('last', '', time() - 36000, '/', ".{$domain['0']}");
     }
     if (isset($_COOKIE['identity'])) {
         setcookie('identity', '', time() - 36000, '/', ".{$domain['0']}");
     }
     Zend_Auth::getInstance()->clearIdentity();
     Zend_Session::destroy();
     Zend_Session::regenerateId();
 }
 /**
  * The default action - show the home page
  */
 public function studentAction()
 {
     $this->_helper->viewRenderer->setNoRender(false);
     $request = $this->getRequest();
     $department = $request->getParam('department_id');
     $degree = $request->getParam('degree_id');
     $batch = $request->getParam('batch');
     if (isset($degree) and isset($department) and isset($batch)) {
         $client = new Zend_Http_Client('http://' . CORE_SERVER . '/batch/getbatchstudent' . "?department_id={$department}" . "&degree_id={$degree}" . "&batch_id={$batch}");
         $client->setCookie('PHPSESSID', $_COOKIE['PHPSESSID']);
         $response = $client->request();
         if ($response->isError()) {
             $remoteErr = 'REMOTE ERROR: (' . $response->getStatus() . ') ' . $response->getHeader('Message');
             throw new Zend_Exception($remoteErr, Zend_Log::ERR);
         } else {
             $jsonContent = $response->getBody($response);
             $students = Zend_Json::decode($jsonContent);
             $this->_helper->logger($jsonContent);
             $this->view->assign('students', $students);
             $this->view->assign('department', $department);
             $this->view->assign('degree', $degree);
             $this->view->assign('batch', $batch);
         }
     }
 }
 public static function login($request)
 {
     $blogPath = SJB_Settings::getSettingByName('blog_path');
     if (empty($blogPath)) {
         return;
     }
     $username = $request['username'];
     $password = $request['password'];
     $userInfo = SJB_UserManager::getUserInfoByUserName($username);
     $userInfo = $userInfo ? base64_encode(serialize($userInfo)) : false;
     $url = SJB_System::getSystemSettings('SITE_URL') . $blogPath . '/wp-login.php';
     $client = new Zend_Http_Client($url, array('useragent' => SJB_Request::getUserAgent(), 'maxredirects' => 0));
     $client->setCookieJar();
     $client->setCookie($_COOKIE);
     $client->setMethod(Zend_Http_Client::POST);
     $client->setParameterPost(array('log' => $username, 'pwd' => $password, 'noSJB' => 1, 'userInfo' => $userInfo, 'wp-submit' => 'Log in'));
     try {
         $response = $client->request();
         foreach ($response->getHeaders() as $key => $header) {
             if ('set-cookie' == strtolower($key)) {
                 if (is_array($header)) {
                     foreach ($header as $val) {
                         header("Set-Cookie: " . $val, false);
                     }
                 } else {
                     header("Set-Cookie: " . $header, false);
                 }
             }
         }
         $_SESSION['wp_cookie_jar'] = @serialize($client->getCookieJar());
     } catch (Exception $ex) {
     }
 }
 static function logout()
 {
     SessionStorage::destroy(SJB_Session::getSessionId());
     $forumPath = SJB_Settings::getSettingByName('forum_path');
     if (empty($forumPath)) {
         return;
     }
     $url = SJB_System::getSystemSettings('SITE_URL') . $forumPath . '/';
     $client = new Zend_Http_Client($url, array('useragent' => SJB_Request::getUserAgent()));
     $client->setCookie($_COOKIE);
     $client->setCookieJar();
     try {
         $response = $client->request();
         $matches = array();
         if (preg_match('/\\.\\/ucp.php\\?mode=logout\\&amp;sid=([\\w\\d]+)"/', $response->getBody(), $matches)) {
             $sid = $matches[1];
             $client->setUri($url . 'ucp.php?mode=logout&sid=' . $sid);
             $response = $client->request();
             foreach ($response->getHeaders() as $key => $header) {
                 if ('set-cookie' == strtolower($key)) {
                     if (is_array($header)) {
                         foreach ($header as $val) {
                             header("Set-Cookie: " . $val, false);
                         }
                     } else {
                         header("Set-Cookie: " . $header, false);
                     }
                 }
             }
         }
     } catch (Exception $ex) {
     }
 }
 /**
  * POST xml data to Google with authorization headers set
  *
  * @param string $xml
  * @param string $uri POST URI
  * @return Zend_Http_Response
  */
 public function post($xml, $uri = null)
 {
     if ($uri == null) {
         $uri = $this->_defaultPostUri;
     }
     if ($uri == null) {
         throw Zend::exception('Zend_Gdata_Exception', 'You must specify an URI to which to post.');
     }
     $this->_httpClient->setUri($uri);
     $this->_httpClient->setConfig(array('maxredirects' => 0));
     $this->_httpClient->setRawData($xml, 'application/atom+xml');
     $response = $this->_httpClient->request('POST');
     //set "S" cookie to avoid future redirects.
     if ($cookie = $response->getHeader('Set-cookie')) {
         list($cookieName, $cookieValue) = explode('=', $cookie, 2);
         $this->_httpClient->setCookie($cookieName, $cookieValue);
     }
     if ($response->isRedirect()) {
         //this usually happens. Re-POST with redirected URI.
         $this->_httpClient->setUri($response->getHeader('Location'));
         $this->_httpClient->setRawData($xml, 'application/atom+xml');
         $response = $this->_httpClient->request('POST');
     }
     if (!$response->isSuccessful()) {
         throw Zend::exception('Zend_Gdata_Exception', 'Post to Google failed.');
     }
     return $response;
 }
Exemple #7
0
 public function _fetchPersonalInfo()
 {
     $faculty_id = $this->getFacultyId();
     $cache = self::getCache('remote');
     $facultyPersonal = $cache->load('facultyPersonal');
     // see if a cache already exists:
     if ($facultyPersonal === false or !isset($facultyPersonal[$faculty_id])) {
         $PROTOCOL = 'http://';
         $URL_STAFF_INFO = $PROTOCOL . CORE_SERVER . '/staff/getinfo' . "?staff_id={$faculty_id}";
         $client = new Zend_Http_Client($URL_STAFF_INFO);
         $client->setCookie('PHPSESSID', $_COOKIE['PHPSESSID']);
         $response = $client->request();
         if ($response->isError()) {
             $remoteErr = 'REMOTE ERROR: (' . $response->getStatus() . ') ' . $response->getMessage();
             Zend_Registry::get('logger')->err($remoteErr);
             throw new Zend_Exception($remoteErr, Zend_Log::ERR);
         } else {
             $jsonContent = $response->getBody();
             $facultyInfo = Zend_Json_Decoder::decode($jsonContent);
             $facultyPersonal[$faculty_id] = $facultyInfo;
             $cache->save($facultyPersonal, 'facultyPersonal');
         }
     }
     return $facultyPersonal[$faculty_id];
 }
Exemple #8
0
 /**
  * POST data to Google with authorization headers set
  *
  * @param mixed $data The Zend_Gdata_App_Entry or XML to post
  * @param string $uri POST URI
  * @return Zend_Http_Response
  * @throws Zend_Gdata_App_Exception
  * @throws Zend_Gdata_App_HttpException
  * @throws Zend_Gdata_App_InvalidArgumentException
  */
 public function post($data, $uri = null)
 {
     require_once 'Zend/Http/Client/Exception.php';
     if (is_string($data)) {
         $rawData = $data;
     } elseif ($data instanceof Zend_Gdata_App_Entry) {
         $rawData = $data->saveXML();
     } else {
         require_once 'Zend/Gdata/App/InvalidArgumentException.php';
         throw new Zend_Gdata_App_InvalidArgumentException('You must specify the data to post as either a string or a child of Zend_Gdata_App_Entry');
     }
     if ($uri == null) {
         $uri = $this->_defaultPostUri;
     }
     if ($uri == null) {
         require_once 'Zend/Gdata/App/InvalidArgumentException.php';
         throw new Zend_Gdata_App_InvalidArgumentException('You must specify an URI to which to post.');
     }
     $this->_httpClient->setUri($uri);
     $this->_httpClient->setConfig(array('maxredirects' => 0));
     $this->_httpClient->setRawData($rawData, 'application/atom+xml');
     try {
         $response = $this->_httpClient->request('POST');
     } catch (Zend_Http_Client_Exception $e) {
         require_once 'Zend/Gdata/App/HttpException.php';
         throw new Zend_Gdata_App_HttpException($e->getMessage(), $e);
     }
     /**
      * set "S" cookie to avoid future redirects.
      */
     if ($cookie = $response->getHeader('Set-cookie')) {
         list($cookieName, $cookieValue) = explode('=', $cookie, 2);
         $this->_httpClient->setCookie($cookieName, $cookieValue);
     }
     if ($response->isRedirect()) {
         /**
          * Re-POST with redirected URI.
          * This happens frequently.
          */
         $this->_httpClient->setUri($response->getHeader('Location'));
         $this->_httpClient->setRawData($rawData, 'application/atom+xml');
         try {
             $response = $this->_httpClient->request('POST');
         } catch (Zend_Http_Client_Exception $e) {
             throw new Zend_Gdata_App_HttpException($e->getMessage(), $e);
         }
     }
     if (!$response->isSuccessful()) {
         require_once 'Zend/Gdata/App/HttpException.php';
         $exception = new Zend_Gdata_App_HttpException('Expected response code 200, got ' . $response->getStatus());
         $exception->setResponse($response);
         throw $exception;
     }
     return $response;
 }
 /**
  * Test we can unset a cookie jar
  *
  */
 public function testUnsetCookieJar()
 {
     // Set the cookie jar just like in testSetNewCookieJar
     $this->client->setCookieJar();
     $this->client->setCookie('cookie', 'value');
     $this->client->setCookie('chocolate', 'chips');
     $jar = $this->client->getCookieJar();
     // Try unsetting the cookiejar
     $this->client->setCookieJar(null);
     $this->assertNull($this->client->getCookieJar(), 'Cookie jar is expected to be null but it is not');
 }
Exemple #10
0
 public static function getMemberInfo($memberId)
 {
     $PROTOCOL = 'http://';
     $membership = self::getMembership($memberId);
     $memberType = strtoupper($membership['member_type_id']);
     Zend_Registry::get('logger')->debug($membership);
     $memberInfo = $membership;
     switch ($memberType) {
         case 'STUDENT':
             $URL_STU_INFO = $PROTOCOL . CORE_SERVER . '/student/getinfo' . "?rollno={$memberId}";
             $client = new Zend_Http_Client($URL_STU_INFO);
             $client->setCookie('PHPSESSID', $_COOKIE['PHPSESSID']);
             $response = $client->request();
             if ($response->isError()) {
                 $remoteErr = 'REMOTE ERROR: (' . $response->getStatus() . ') ' . $response->getMessage();
                 Zend_Registry::get('logger')->err($remoteErr);
                 /**
                  * @todo Surpress Remote Error.
                  */
                 //throw new Zend_Exception ( $remoteErr, Zend_Log::ERR );
                 $memberInfo['info'] = array();
                 return $memberInfo;
             }
             $jsonContent = $response->getBody($response);
             $memberInfo['info'] = Zend_Json_Decoder::decode($jsonContent);
             return $memberInfo;
         case 'STAFF':
             $URL_STAFF_INFO = $PROTOCOL . CORE_SERVER . '/staff/getinfo' . "?staff_id={$memberId}";
             $client = new Zend_Http_Client($URL_STAFF_INFO);
             $client->setCookie('PHPSESSID', $_COOKIE['PHPSESSID']);
             $response = $client->request();
             if ($response->isError()) {
                 $remoteErr = 'REMOTE ERROR: (' . $response->getStatus() . ') ' . $response->getMessage();
                 Zend_Registry::get('logger')->err($remoteErr);
                 /**
                  * @todo Surpress Remote Error.
                  */
                 //throw new Zend_Exception ( $remoteErr, Zend_Log::ERR );
                 $memberInfo['info'] = array();
                 return $memberInfo;
             }
             $jsonContent = $response->getBody($response);
             $memberInfo['info'] = Zend_Json_Decoder::decode($jsonContent);
             return $memberInfo;
         case 'BOOKBANK':
             $memberInfo['info'] = array('first_name' => strtoupper($memberId));
             return $memberInfo;
         default:
             throw new Zend_Exception('Unknown member type : "' . $memberType . '"', Zend_Log::WARN);
     }
     // TODO Name, Department etc
 }
 public static function fetchUrl($url)
 {
     $http_client = new Zend_Http_Client();
     $http_client->setConfig(array('maxredirects' => 1, 'timeout' => 30, 'keepalive' => false));
     $http_client->setMethod(Zend_Http_Client::GET);
     $http_client->setUri($url);
     $http_client->setCookie('int-SC2', '1');
     $response = $http_client->request();
     if ($response->isError()) {
         throw new Exception('Http request at "' . $url . '" failed with error code "' . $response->getStatus() . '"');
     }
     return utf8_decode($response->getBody());
 }
Exemple #12
0
 /**
  * Add a ban expression to the varnish ban list 
  * If $perClient is set to true, the BAN will be only for a per-client cached object
  *
  * @param unknown_type $regexp
  * @param unknown_type $perClient
  */
 public function banRegexp($regexp, $perClient = false)
 {
     if (!Mage::getStoreConfig('varnish/varnish/active')) {
         return false;
     }
     $httpAdapter = new Zend_Http_Client(Mage::getBaseUrl());
     $httpAdapter->setHeaders("X-Magento-Regexp", $regexp);
     if ($perClient) {
         $httpAdapter->setCookie('frontend', Mage::app()->getRequest()->getCookie('frontend'));
     }
     $response = $httpAdapter->request("BAN");
     return $response;
 }
Exemple #13
0
 /**
  * Make sure we can set cookie objects with a jar
  *
  */
 public function testSetCookieObjectJar()
 {
     $this->client->setUri($this->baseuri . 'testCookies.php');
     $this->client->setCookieJar();
     $refuri = $this->client->getUri();
     $cookies = array(Zend_Http_Cookie::fromString('chocolate=chips', $refuri), Zend_Http_Cookie::fromString('crumble=apple', $refuri));
     $strcookies = array();
     foreach ($cookies as $c) {
         $this->client->setCookie($c);
         $strcookies[$c->getName()] = $c->getValue();
     }
     $res = $this->client->request();
     $this->assertEquals($res->getBody(), serialize($strcookies), 'Response body does not contain the expected cookies');
 }
Exemple #14
0
 /**
  * 
  * @param string $url
  * @param array $param
  * @param string $method
  * @return string
  */
 protected function _request($url, $param = array(), $method = Zend_Http_Client::POST)
 {
     if ($this->_client === null) {
         $config = array('useragent' => 'Mozilla/5.0 (Windows NT 6.1; rv:22.0) Gecko/20100101 Firefox/44.0', 'encodecookies' => false, 'timeout' => 180);
         $this->_client = new Zend_Http_Client($url, $config);
         $this->_client->setCookieJar();
     }
     $this->_client->resetParameters()->setUri($url);
     if (count($param['post']) > 0) {
         foreach ($param['post'] as $name => $value) {
             $this->_client->setParameterPost($name, $value);
         }
     }
     if (count($param['get']) > 0) {
         foreach ($param['get'] as $name => $value) {
             $this->_client->setParameterPost($name, $value);
         }
     }
     if (count($param['file']) > 0) {
         foreach ($param['file'] as $name => $value) {
             $this->_client->setFileUpload($value, $name);
         }
     }
     if (count($param['cookie']) > 0) {
         foreach ($param['cookie'] as $name => $value) {
             $this->_client->setCookie($name, $value);
         }
     }
     if (count($this->_cookies) > 0) {
         foreach ($this->_cookies as $cookie) {
             $this->_client->setCookie($cookie);
         }
     }
     $response = $this->_client->request($method);
     $this->_cookies = $this->_client->getCookieJar()->getAllCookies();
     return $response->getBody();
 }
Exemple #15
0
 /**
  * Faz o login na wiki usando a API
  *
  * @param string $url
  * @param string $user
  * @param string $password
  *
  * @return boolean|string   Retorna TRUE ou o erro encontrado
  */
 static function login($url, $user = null, $password = null)
 {
     // Se não foi fornecido um usuário/senha, irá considerar que a url é o tipo de usuário
     if (is_null($user)) {
         $usuario = self::getUser($url);
         $url = $usuario['apiurl'];
         $user = $usuario['user_name'];
         $password = $usuario['user_password'];
     }
     // Cria o cliente
     $client = new Zend_Http_Client();
     // Faz o login inicial
     $client->setUri($url);
     $client->setHeaders('Accept-Encoding', 'none');
     $client->setParameterPost('action', 'login');
     $client->setParameterPost('lgname', $user);
     $client->setParameterPost('lgpassword', $password);
     $client->setParameterPost('format', 'php');
     $response = $client->request(Zend_Http_Client::POST);
     $result = unserialize($response->getBody());
     //RW_Debug::dump($response);
     //RW_Debug::dump($result);
     $client->setParameterPost('lgtoken', $result['login']['token']);
     $client->setCookie($result['login']['cookieprefix'] . '_session', $result['login']['sessionid']);
     // Recupera o token
     $response = $client->request(Zend_Http_Client::POST);
     $result = unserialize($response->getBody());
     //RW_Debug::dump($response);
     //RW_Debug::dump($result);
     //RW_Debug::dump($client->getLastRequest());
     // Configura o Cookie da Sessão
     if ($result['login']['result'] === 'Success') {
         setcookie($result['login']['cookieprefix'] . 'LoggedOut', '-', 1, '/', $_SERVER['HTTP_HOST'], false, true);
         setcookie($result['login']['cookieprefix'] . '_session', $result['login']['sessionid'], time() + 7200, '/', $_SERVER['HTTP_HOST'], false, true);
         setcookie($result['login']['cookieprefix'] . 'UserName', $result['login']['lgusername'], time() + 7200, '/', $_SERVER['HTTP_HOST'], false, true);
         setcookie($result['login']['cookieprefix'] . 'UserID', $result['login']['lguserid'], time() + 7200, '/', $_SERVER['HTTP_HOST'], false, true);
         setcookie($result['login']['cookieprefix'] . 'Token', $result['login']['lgtoken'], time() + 7200, '/', $_SERVER['HTTP_HOST'], false, true);
         return true;
     } else {
         return $result['login']['result'];
     }
 }
 public function flush_postAction()
 {
     $session = Mage::getSingleton('core/session');
     $post = $this->getRequest()->getPost();
     $url = trim($post['flush_form']['url']);
     if (!preg_match('|https?://|', $url)) {
         $session->addError($this->__('Please use a full URL, start with "http://" or "https://"'));
     }
     $urlParts = parse_url($url);
     if (false === $urlParts || empty($urlParts['host'])) {
         $session->addError($this->__('Invalid URL: <b>%s</b>.', $url));
         $session->setData('JeroenVermeulen_BlockCache_PurgeURL', '');
     } else {
         $flushUrl = $url;
         if (false === strpos($flushUrl, '?')) {
             $flushUrl .= '?jvflush';
         } else {
             $flushUrl .= '&jvflush';
         }
         Mage::log(sprintf('JeroenVermeulen_BlockCache_Adminhtml_Jv_BlockcacheController "%s"', $flushUrl), Zend_Log::INFO, 'system.log');
         $httpClient = new Zend_Http_Client($flushUrl);
         $httpClient->setConfig(array('timeout' => 60));
         $httpClient->setCookie('jvflush', '1');
         $httpClient->setConfig(array('httpversion' => Zend_Http_Client::HTTP_0));
         $response = $httpClient->request();
         /** @noinspection HtmlUnknownTarget */
         $sLink = sprintf('<a href="%s" target="_blank">%s</a>', $url, $url);
         if ($response->isSuccessful()) {
             $msg = $this->__('The URL %s has been flushed.', $sLink);
             Mage::log($msg, Zend_Log::INFO);
             $session->addSuccess($msg);
         } else {
             $msg = $this->__('Error flushing URL %s.', $sLink);
             Mage::log($msg, Zend_Log::INFO);
             $session->addError($msg);
         }
         $session->setData('JeroenVermeulen_BlockCache_FlushURL', $url);
     }
     $this->_redirect('*/*/flush');
     // Redirect to index action
 }
Exemple #17
0
 /**
  * POST xml data to Google with authorization headers set
  *
  * @param string $xml
  * @param string $uri POST URI
  * @return Zend_Http_Response
  * @throws Zend_Gdata_Exception
  * @throws Zend_Gdata_HttpException
  * @throws Zend_Gdata_InvalidArgumentException
  */
 public function post($xml, $uri = null)
 {
     if ($uri == null) {
         $uri = $this->_defaultPostUri;
     }
     if ($uri == null) {
         throw new Zend_Gdata_InvalidArgumentException('You must specify an URI to which to post.');
     }
     $this->_httpClient->setUri($uri);
     $this->_httpClient->setConfig(array('maxredirects' => 0));
     $this->_httpClient->setRawData($xml, 'application/atom+xml');
     try {
         $response = $this->_httpClient->request('POST');
     } catch (Zend_Http_Client_Exception $e) {
         throw new Zend_Gdata_HttpException($e->getMessage(), $e);
     }
     /**
      * set "S" cookie to avoid future redirects.
      */
     if ($cookie = $response->getHeader('Set-cookie')) {
         list($cookieName, $cookieValue) = explode('=', $cookie, 2);
         $this->_httpClient->setCookie($cookieName, $cookieValue);
     }
     if ($response->isRedirect()) {
         /**
          * Re-POST with redirected URI.
          * This happens frequently.
          */
         $this->_httpClient->setUri($response->getHeader('Location'));
         $this->_httpClient->setRawData($xml, 'application/atom+xml');
         try {
             $response = $this->_httpClient->request('POST');
         } catch (Zend_Http_Client_Exception $e) {
             throw new Zend_Gdata_HttpException($e->getMessage(), $e);
         }
     }
     if (!$response->isSuccessful()) {
         throw new Zend_Gdata_Exception('Post to Google failed. Reason: ' . $response->getBody());
     }
     return $response;
 }
 /**
  * Get information about current session.
  * Enter description here ...
  * @throws Zend_Exception
  * @return array Information about current session.
  */
 public static function fetchSessionInfo()
 {
     $cache = self::getCache('remote');
     $acadSession = $cache->load('academicSession');
     // see if a cache already exists:
     if ($acadSession === false) {
         $sessionInfoURL = 'http://' . CORE_SERVER . '/session/getsessioninfo';
         $client = new Zend_Http_Client($sessionInfoURL);
         $client->setCookie('PHPSESSID', $_COOKIE['PHPSESSID']);
         $response = $client->request();
         if ($response->isError()) {
             $remoteErr = 'ERROR from ' . CORE_SERVER . ' : (' . $response->getStatus() . ') ' . $response->getMessage() . ', i.e. ' . $response->getHeader('Message');
             throw new Zend_Exception($remoteErr, Zend_Log::ERR);
         } else {
             $jsonContent = $response->getBody();
             $acadSession = Zend_Json_Decoder::decode($jsonContent);
             $cache->save($acadSession, 'academicSession');
         }
     }
     return $acadSession;
 }
Exemple #19
0
 /**
  * Get information about current session.
  * Enter description here ...
  * @throws Zend_Exception
  * @return array Information about current session.
  */
 protected static function fetchGroupInfo($department, $degree)
 {
     $cache = self::getCache('remote');
     $classGroups = $cache->load('classGroups');
     // see if a cache already exists:
     if ($classGroups === false || !isset($classGroups[$degree][$department])) {
         $groupsInfoURL = 'http://' . CORE_SERVER . '/groups/getgroup' . "?department_id={$department}" . "&degree_id={$degree}";
         $client = new Zend_Http_Client($groupsInfoURL);
         $client->setCookie('PHPSESSID', $_COOKIE['PHPSESSID']);
         $response = $client->request();
         if ($response->isError()) {
             $remoteErr = 'REMOTE ERROR: (' . $response->getStatus() . ') ' . $response->getMessage();
             throw new Zend_Exception($remoteErr, Zend_Log::ERR);
         } else {
             $jsonContent = $response->getBody();
             $classGroups[$degree][$department] = Zend_Json_Decoder::decode($jsonContent);
             $cache->save($classGroups, 'classGroups');
         }
     } else {
         self::getLogger()->log('classGroups from cache', Zend_Log::INFO);
         self::getLogger()->log($classGroups, Zend_Log::DEBUG);
     }
     return $classGroups[$degree][$department];
 }
 /**
  * Get information about current session.
  * Enter description here ...
  * @throws Zend_Exception
  * @return array Information about current session.
  */
 protected static function _fetchSlaveInfo($masterDepartment)
 {
     $cache = self::getCache('remote');
     $slaveDept = $cache->load('slaveDept');
     // see if a cache already exists:
     if ($slaveDept === false || !isset($slaveDept[$masterDepartment])) {
         $groupsInfoURL = 'http://' . CORE_SERVER . '/semesterdegree/getslaveinfo' . "?masterDepartment={$masterDepartment}" . '&currentSession=true' . '&degree=true' . '&semseter=true';
         $client = new Zend_Http_Client($groupsInfoURL);
         $client->setCookie('PHPSESSID', $_COOKIE['PHPSESSID']);
         $response = $client->request();
         if ($response->isError()) {
             $remoteErr = 'REMOTE ERROR: (' . $response->getStatus() . ') ' . $response->getMessage();
             throw new Zend_Exception($remoteErr, Zend_Log::ERR);
         } else {
             $jsonContent = $response->getBody();
             $slaveDept[$masterDepartment] = Zend_Json_Decoder::decode($jsonContent);
             $cache->save($slaveDept, 'slaveDept');
         }
     } else {
         self::getLogger()->log('$slaveDept from cache', Zend_Log::INFO);
         self::getLogger()->log($slaveDept, Zend_Log::DEBUG);
     }
     return $slaveDept[$masterDepartment];
 }
 private function findClassSubjects($class_id)
 {
     //Zend_Registry::get('logger')->debug('member_id may be sent in as parameter'');
     //Zend_Registry::get('logger')->debug($class_id);
     $httpClient = new Zend_Http_Client('http://' . ACADEMIC_SERVER . '/class/getclasssubjects');
     $httpClient->setCookie('PHPSESSID', $_COOKIE['PHPSESSID']);
     $httpClient->setMethod('POST');
     $httpClient->setParameterPost(array('class_id' => $class_id, 'format' => 'json'));
     $response = $httpClient->request();
     if ($response->isError()) {
         return false;
     } else {
         $json_response = $response->getBody($response);
         $class_subjects = Zend_Json::decode($json_response);
         $subject_ids = array_keys($class_subjects);
         return $subject_ids;
     }
 }
 private function saveToTnp($batch_info)
 {
     $httpClient = new Zend_Http_Client('http://tnp.aceambala.com/batch/savebatch');
     $httpClient->setCookie('PHPSESSID', $_COOKIE['PHPSESSID']);
     $httpClient->setMethod('POST');
     $httpClient->setParameterPost(array('myarray' => array('batch_info' => $batch_info)));
     $response = $httpClient->request();
     if ($response->isError()) {
         return false;
     } else {
         Zend_Registry::get('logger')->debug('Batch Registered in Tnp');
         return true;
     }
 }
 private function saveToTnp($class_info)
 {
     $httpClient = new Zend_Http_Client('http://' . TNP_SERVER . '/class/saveclass');
     $httpClient->setCookie('PHPSESSID', $_COOKIE['PHPSESSID']);
     $httpClient->setMethod('POST');
     $httpClient->setParameterPost(array('myarray' => array('class_info' => $class_info)));
     $response = $httpClient->request();
     if ($response->isError()) {
         return false;
     } else {
         Zend_Registry::get('logger')->debug('Class Registered in Tnp');
         return true;
     }
 }
 public function saveAction()
 {
     $params['member_id'] = $this->_applicant->member_id;
     $params['department_id'] = $this->_applicant->department_id;
     $params['programme_id'] = $this->_applicant->programme_id;
     $params['semester_id'] = $this->_applicant->semester_id;
     print_r($params);
     $PROTOCOL = 'http://';
     $URL = $PROTOCOL . ACADEMIC_SERVER . '/profile' . '?' . http_build_query($params);
     $client = new Zend_Http_Client($URL);
     $client->setCookie('PHPSESSID', $_COOKIE['PHPSESSID']);
     //$response = $client->request();
     $this->_redirect($URL);
 }
 private function prepareDataForExport($member_ids)
 {
     $info_to_export = array();
     if (!empty($member_ids) and is_array($member_ids)) {
         foreach ($member_ids as $member_id) {
             $httpClient = new Zend_Http_Client('http://' . AUTH_SERVER . '/index/finddepartment');
             $httpClient->setCookie('PHPSESSID', $_COOKIE['PHPSESSID']);
             $httpClient->setMethod('POST');
             $httpClient->setParameterPost(array('member_id' => $member_id, 'format' => 'json'));
             $response = $httpClient->request();
             if ($response->isError()) {
             } else {
                 $jsonContent = $response->getBody($response);
                 $department_info = Zend_Json::decode($jsonContent);
             }
             $info_to_export[$member_id]['Department'] = $department_info[0];
             /*
              * Personal Info
              */
             $class_ids = $this->getAllClassIds($member_id);
             ////Zend_Registryget('logger')->debug($class_ids);
             if (is_array($class_ids)) {
                 $class_info = $this->findStuClassInfo($member_id, array_pop($class_ids));
                 $info_to_export[$member_id]['roll_number'] = $class_info['roll_no'];
             } else {
                 $info_to_export[$member_id]['roll_number'] = false;
             }
             $info_to_export[$member_id]['registration_id'] = $this->findRegistrationInfo($member_id);
             $critical_info = $this->findCriticalInfo($member_id);
             $info_to_export[$member_id]['first_name'] = $critical_info['first_name'];
             $info_to_export[$member_id]['last_name'] = $critical_info['last_name'];
             $info_to_export[$member_id]['middle_name'] = $critical_info['middle_name'];
             $info_to_export[$member_id]['dob'] = $critical_info['dob'];
             $info_to_export[$member_id]['gender'] = $critical_info['gender'];
             /*
              * Fathers name
              */
             $relative_id = $this->findRelationId('FATHER');
             $relative_info = $this->findRelativeInfo($member_id, $relative_id);
             if (empty($relative_info['name'])) {
                 $info_to_export[$member_id]['father_name'] = '----';
             } else {
                 $info_to_export[$member_id]['father_name'] = $relative_info['name'];
             }
             /*
              * Address info
              */
             $address_info = $this->findAddressInfo($member_id);
             if (!empty($address_info['MAILING'])) {
                 $address_req = $address_info['MAILING'];
                 $info_to_export[$member_id]['postal_code'] = $address_req['postal_code'];
                 $info_to_export[$member_id]['city'] = $address_req['city'];
                 $info_to_export[$member_id]['district'] = $address_req['district'];
                 $info_to_export[$member_id]['state'] = $address_req['state'];
                 $info_to_export[$member_id]['address'] = $address_req['address'];
             } else {
                 $info_to_export[$member_id]['postal_code'] = '----';
                 $info_to_export[$member_id]['city'] = '----';
                 $info_to_export[$member_id]['district'] = '----';
                 $info_to_export[$member_id]['state'] = '----';
                 $info_to_export[$member_id]['address'] = '----';
             }
             foreach ($info_to_export as $members_id => $members_info) {
                 foreach ($members_info as $key => $value) {
                     $info_to_export[$member_id][$key] = strtoupper($value);
                 }
             }
             /*
              * Contact Info
              */
             $contact = new Core_Model_Mapper_MemberContacts();
             $all_contact_types = $contact->fetchAllContactTypes();
             $home_landline = array_search('HOME LANDLINE', $all_contact_types);
             $contact_info = $this->findContactsInfo($member_id);
             //over write; no problem
             $info_to_export[$member_id]['home_landline'] = $contact_info[$home_landline]['contact_details'];
             $home_mobile = array_search('HOME MOBILE', $all_contact_types);
             $info_to_export[$member_id]['home_mobile'] = $contact_info[$home_mobile]['contact_details'];
             $email = array_search('EMAIL', $all_contact_types);
             $info_to_export[$member_id]['email'] = $contact_info[$email]['contact_details'];
         }
         return $info_to_export;
     }
 }
 public function setacademicAction()
 {
     $this->_helper->viewRenderer->setNoRender(TRUE);
     $this->_helper->layout()->disableLayout();
     $request = $this->getRequest();
     $params = array_diff($request->getParams(), $request->getUserParams());
     $params['member_id'] = $this->_applicant->member_id;
     $params['department_id'] = $this->_applicant->department_id;
     $params['programme_id'] = $this->_applicant->programme_id;
     $params['semester_id'] = $this->_applicant->semester_id;
     $params['roll_no'] = $this->_applicant->roll_no;
     foreach ($params as $colName => $value) {
         $value = is_array($value) ? $value : htmlentities(trim($value));
         $this->_applicant_academic->{$colName} = $value;
     }
     echo 'Following information recieved:<br/>';
     foreach ($params as $colName => $value) {
         $value = is_array($value) ? var_export($value, true) : htmlentities(trim($value));
         echo '<b>' . ucwords(str_ireplace('_', ' ', $colName)) . '</b> : ' . $value . '<br/>';
     }
     $PROTOCOL = 'http://';
     $URL = $PROTOCOL . ACADEMIC_SERVER . '/student/saveprofile' . '?' . http_build_query($params);
     $client = new Zend_Http_Client($URL);
     $client->setCookie('PHPSESSID', $_COOKIE['PHPSESSID']);
     $response = $client->request();
     if ($response->isError()) {
         $remoteErr = 'REMOTE ERROR: (' . $response->getStatus() . ') ' . $response->getHeader('Message');
         throw new Zend_Exception($remoteErr, Zend_Log::ERR);
     }
 }
 /**
  * @group slow
  */
 public function testController()
 {
     $d = Zend_Registry::get('testDomain');
     $testCookie = md5(uniqid('testId', true));
     $client = new Zend_Http_Client("http://{$d}/kwf/test/kwf_exception_test/access-denied");
     $client->setCookie('unitTest', $testCookie);
     $response = $client->request();
     $this->assertEquals(401, $response->getStatus());
     $client = new Zend_Http_Client("http://{$d}/kwf/test/kwf_exception_test/not-found");
     $client->setCookie('unitTest', $testCookie);
     $response = $client->request();
     $this->assertEquals(404, $response->getStatus());
     $client = new Zend_Http_Client("http://{$d}/kwf/test/kwf_exception_test/client");
     $client->setCookie('unitTest', $testCookie);
     $response = $client->request();
     $this->assertEquals(200, $response->getStatus());
     $this->assertContains('client exception', $response->getBody());
     $client = new Zend_Http_Client("http://{$d}/kwf/test/kwf_exception_test/exception");
     $client->setCookie('unitTest', $testCookie);
     $response = $client->request();
     $this->assertEquals(500, $response->getStatus());
     $client = new Zend_Http_Client("http://{$d}/kwf/test/kwf_exception_test/exception-other");
     $client->setCookie('unitTest', $testCookie);
     $response = $client->request();
     $this->assertEquals(500, $response->getStatus());
 }
Exemple #28
0
 /**
  * Fetch class students from core server.
  * 
  * @param Acad_Model_Class $class
  * @param string $group that belongs to class.
  * @throws Zend_Exception
  * @return array class students.
  */
 public static function fetchSemesterStudents(Acad_Model_Class $class, $group)
 {
     $department = $class->getDepartment();
     $degree = $class->getDegree();
     $semester = $class->getSemester();
     $cacheManager = Zend_Registry::get('cacheManager');
     $cache = $cacheManager->getCache('remote');
     if (isset($group)) {
         $stuCache = strtolower($department . $degree . $semester . $group);
     } else {
         $stuCache = strtolower($department . $degree . $semester);
     }
     $students = $cache->load($stuCache);
     // see if a cache already exists:
     if ($students === false) {
         $semesterStuURL = 'http://' . CORE_SERVER . '/semester/getstudents';
         $client = new Zend_Http_Client($semesterStuURL);
         $client->setCookie('PHPSESSID', $_COOKIE['PHPSESSID'])->setParameterGet('department_id', $department)->setParameterGet('degree_id', $degree)->setParameterGet('semester_id', $semester);
         if (isset($group)) {
             $client->setParameterGet('group_id', $group);
         }
         $response = $client->request();
         if ($response->isError()) {
             $remoteErr = 'REMOTE ERROR: (' . $response->getStatus() . ') ' . $response->getMessage();
             throw new Zend_Exception($remoteErr, Zend_Log::ERR);
         } else {
             $jsonContent = $response->getBody();
             $students = Zend_Json_Decoder::decode($jsonContent);
             $cache->save($students, $stuCache);
         }
     }
     return $students;
 }
Exemple #29
0
 /**
  * PUT data with client object
  *
  * @param mixed $data The Zend_Gdata_App_Entry or XML to post
  * @param string $uri PUT URI
  * @return Zend_Http_Response
  * @throws Zend_Gdata_App_Exception
  * @throws Zend_Gdata_App_HttpException
  * @throws Zend_Gdata_App_InvalidArgumentException
  */
 public function put($data, $uri = null, $remainingRedirects = null)
 {
     require_once 'Zend/Http/Client/Exception.php';
     if ($remainingRedirects === null) {
         $remainingRedirects = self::getMaxRedirects();
     }
     if (is_string($data)) {
         $rawData = $data;
     } elseif ($data instanceof Zend_Gdata_App_Entry) {
         $rawData = $data->saveXML();
     } else {
         require_once 'Zend/Gdata/App/InvalidArgumentException.php';
         throw new Zend_Gdata_App_InvalidArgumentException('You must specify the data to post as either a string or a child of Zend_Gdata_App_Entry');
     }
     if ($uri === null) {
         if ($data instanceof Zend_Gdata_App_Entry) {
             $editLink = $data->getEditLink();
             if ($editLink != null) {
                 $uri = $editLink->getHref();
             }
         }
     }
     if ($uri === null) {
         require_once 'Zend/Gdata/App/InvalidArgumentException.php';
         throw new Zend_Gdata_App_InvalidArgumentException('You must specify an URI to which to put.');
     }
     $this->_httpClient->setUri($uri);
     $this->_httpClient->setConfig(array('maxredirects' => 0));
     $this->_httpClient->setRawData($rawData, 'application/atom+xml');
     try {
         if (Zend_Gdata_App::getHttpMethodOverride()) {
             $this->_httpClient->setHeaders(array('X-HTTP-Method-Override: PUT', 'Content-Type: application/atom+xml'));
             $response = $this->_httpClient->request('POST');
         } else {
             $this->_httpClient->setHeaders('Content-Type', 'application/atom+xml');
             $response = $this->_httpClient->request('PUT');
         }
     } catch (Zend_Http_Client_Exception $e) {
         require_once 'Zend/Gdata/App/HttpException.php';
         throw new Zend_Gdata_App_HttpException($e->getMessage(), $e);
     }
     /**
      * set "S" cookie to avoid future redirects.
      */
     if ($cookie = $response->getHeader('Set-cookie')) {
         list($cookieName, $cookieValue) = explode('=', $cookie, 2);
         $this->_httpClient->setCookie($cookieName, $cookieValue);
     }
     if ($response->isRedirect()) {
         if ($remainingRedirects > 0) {
             $response = $this->put($data, $uri, $remainingRedirects - 1);
         } else {
             throw new Zend_Gdata_App_HttpException('No more redirects allowed', null, $response);
         }
     }
     if (!$response->isSuccessful()) {
         require_once 'Zend/Gdata/App/HttpException.php';
         $exception = new Zend_Gdata_App_HttpException('Expected response code 200, got ' . $response->getStatus());
         $exception->setResponse($response);
         throw $exception;
     }
     return $response;
 }