zmodel = Mage::getModel('livechat/livechat')->load(1); $zoptions = $this->zmodel->_data; /* $object = Mage::getModel('livechat/livechat')->load(1); $object->setTitle('This is a changed title'); $object->save();*/ $password = ""; if ($zoptions['salt'] != "") { $password = "password"; } $authenticated = ""; $error = array(); $gotologin = 0; if ($this->getRequest()->getParam('deactivate')=="yes") { $this->zmodel->setSalt(''); $this->zmodel->setCode('zopim'); } else if ($this->getRequest()->getParam('zopimusername')!="") { // logging in if ($this->getRequest()->getParam('zopimUseSSL')!="") { $this->zmodel->setUseSSL('zopimUseSSL'); } else { $this->zmodel->setUseSSL(''); } $zopimusername = $this->getRequest()->getParam('zopimusername'); $zopimpassword = $this->getRequest()->getParam('zopimpassword'); $logindata = array("email" => $zopimusername, "password" => $zopimpassword); $loginresult = $this->do_post_request(ZOPIM_LOGIN_URL, $logindata); $loginresult = Zend_Json::decode($loginresult); if (isset($loginresult["error"])) { $error["login"] = "Could not log in to Zopim. Please check your login details. If problem persists, try connecting without SSL enabled."; $gotologin = 1; $this->zmodel->setSalt(''); } else if (isset($loginresult["salt"])) { $this->zmodel->setUsername($zopimusername); $this->zmodel->setSalt($loginresult["salt"]); $account = Zend_Json::decode($this->do_post_request(ZOPIM_GETACCOUNTDETAILS_URL, array("salt" => $loginresult["salt"]))); if (isset($account)) { $this->zmodel->setCode($account["account_key"]); if ($this->zmodel->getGreetings() == "") { $jsongreetings = Zend_Json::encode($account["settings"]["greetings"]); $this->zmodel->setGreetings($jsongreetings); } } } else { $this->zmodel->setSalt(''); $error["login"] = "Could not log in to Zopim. We were unable to contact Zopim servers. Please check with your server administrator to ensure that PHP Curl is installed and permissions are set correctly."; } } else if ($this->getRequest()->getParam('zopimfirstname')!="") { // signing up if ($this->getRequest()->getParam('zopimUseSSL')!="") { $this->zmodel->setUseSSL('zopimUseSSL'); } else { $this->zmodel->setUseSSL(''); } $createdata = array( "email" => $this->getRequest()->getParam('zopimnewemail'), "first_name" => $this->getRequest()->getParam('zopimfirstname'), "last_name" => $this->getRequest()->getParam('zopimlastname'), "display_name" => $this->getRequest()->getParam('zopimfirstname')." ".$this->getRequest()->getParam('zopimlastname'), "eref" => "", "source" => "magento", "recaptcha_challenge_field" => $this->getRequest()->getParam('recaptcha_challenge_field'), "recaptcha_response_field" => $this->getRequest()->getParam('recaptcha_response_field') ); $signupresult = Zend_Json::decode($this->do_post_request(ZOPIM_SIGNUP_URL, $createdata)); if (isset($signupresult["error"])) { $error["auth"] = "
Error during activation: ".$signupresult["error"]." Please try again.
"; } else if (isset($signupresult["account_key"])) { $message = "Thank you for signing up. Please check your mail for your password to complete the process. "; $gotologin = 1; } else { $error["auth"] = "Could not activate account. The Magento installation was unable to contact Zopim servers. Please check with your server administrator to ensure that PHP Curl is installed and permissions are set correctly."; } } $this->zmodel->save(); if ($this->zmodel->getCode() != "" && $this->zmodel->getCode() != "zopim") { if (isset($account)) { $accountDetails = $account; } else { $accountDetails = Zend_Json::decode($this->do_post_request(ZOPIM_GETACCOUNTDETAILS_URL, array("salt" => $this->zmodel->getSalt()))); } if (!isset($accountDetails) || isset($accountDetails["error"])) { $gotologin = 1; $error["auth"] = '

Account no longer linked!

We could not verify your Zopim account. Please check your password and try again. '; } else { $authenticated = "ok"; } } if (isset($error["auth"])) { $html = '

'; } else if (isset($error["login"])) { $html = '

'; } else if (isset($message)) { $html = '

'; } else { $html = ' '; } if ($authenticated == "ok") { if ($accountDetails["package_id"]=="trial") { $accountDetails["package_id"] = "Free Lite Package + 14 Days Full-features"; } else { $accountDetails["package_id"] .= " Package"; } $html .= '

Zopim Account Configuration

Successfully connected to Zopim


Deactivate
Currently Activated Account
'.$this->zmodel->getUsername().'
'.$accountDetails["package_id"].'

You may now proceed to the dashboard to chat with customers, customize your widget or enable instant messaging integration through the menu.

'; } else { $waschecked = ""; if ($this->getRequest()->getParam('zopimfirstname')) { $waschecked = "checked"; } $html .= '

Account Configuration

'; // .$this->getRequest()->getParam('abc') $html .= '
Select A Setup
Give me a new account — absolutely free!
I already have a Zopim account

'; $html .= ' "; } return $html; } private function curPageURL() { $pageURL = 'http'; if (isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] == "on") {$pageURL .= "s";} $pageURL .= "://"; if ($_SERVER["SERVER_PORT"] != "80") { $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"]; } else { $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"]; } $pageURL = preg_replace("/\?.*$/", "", $pageURL); return $pageURL; } private function do_post_request($url, $_data) { if ($this->zmodel->getUseSSL() != "zopimUseSSL") { $url = str_replace("https", "http", $url); } $data = array(); while(list($n,$v) = each($_data)){ $data[] = urlencode($n)."=".urlencode($v); } $data = implode('&', $data); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($ch); curl_close($ch); return $response; } }