/admin/controller/module/jivosite.php
PHP | 309 lines | 241 code | 68 blank | 0 comment | 54 complexity | b2b81feb294dd3f510365affdb6c4ae4 MD5 | raw file
- <?php
- class ControllerModuleJivosite extends Controller {
- private $error = array();
- public function index() {
- $this->load->language('module/jivosite');
- $this->load->model('setting/setting');
- $this->document->setTitle($this->language->get('heading_title'));
- $jivlang = $this->config->get('config_admin_language');
- if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
- $query['partnerId'] = $this->request->post['jivosite_partnerId'];
- $query['partnerPassword'] = $this->request->post['jivosite_partnerPassword'];
- $query['siteUrl'] = $this->request->post['jivosite_siteUrl'];
- $query['email'] = $this->request->post['jivosite_email'];
- $query['userPassword'] = $this->request->post['jivosite_userPassword'];
- $query['userDisplayName'] = $this->request->post['jivosite_userDisplayName'];
- $authToken = md5(time().HTTPS_CATALOG);
- $query['authToken'] = $authToken;
- $query['agentId'] = 2469;
- $query['lang'] = $jivlang;
- $content = http_build_query($query);
- if (ini_get('allow_url_fopen')){
- $useCurl = false;
- } elseif (!extension_loaded('curl')) {
- if (!dl('curl.so')) {
- $useCurl = false;
- } else {
- $useCurl = true;
- }
- } else {
- $useCurl = true;
- }
- try {
- $path = "https://admin.jivosite.com/integration/install";
- if (!extension_loaded('openssl')){
- $path = str_replace('https:','http:',$path);
- }
- if ($useCurl){
- if ( $curl = curl_init() ) {
- curl_setopt($curl, CURLOPT_URL, $path);
- curl_setopt($curl, CURLOPT_RETURNTRANSFER,true);
- curl_setopt($curl, CURLOPT_POST, true);
- curl_setopt($curl, CURLOPT_POSTFIELDS, $content);
- $responce = curl_exec($curl);
- curl_close($curl);
- }
- } else {
- $responce = file_get_contents(
- $path,
- false,
- stream_context_create(
- array(
- 'http' => array(
- 'method' => 'POST',
- 'header' => 'Content-Type: application/x-www-form-urlencoded',
- 'content' => $content
- )
- )
- )
- );
- }
- if ($responce) {
- if (strstr($responce,'Error')){
- $this->error['jiverror'] = $responce;
- } else {
- $this->request->post['jivosite_widget_id'] = $responce;
- $this->request->post['jivosite_authToken'] = $authToken;
- $this->model_setting_setting->editSetting('jivosite', $this->request->post);
- $this->session->data['success'] = $this->language->get('text_success');
- if (isset($this->request->get['loginfalse'])) {
- $this->response->redirect($this->url->link('module/jivosite/inlogin', 'token=' . $this->session->data['token'], 'SSL'));
- }
- else {
- $this->response->redirect($this->url->link('extension/module', 'token=' . $this->session->data['token'], 'SSL'));
- }
- }
- }
- } catch (Exception $e) {
- _e("Connection error",'jivosite');
- }
-
- }
- $data['heading_title'] = $this->language->get('heading_title2');
- $data['text_edit'] = $this->language->get('text_edit');
- $data['text_enabled'] = $this->language->get('text_enabled');
- $data['text_disabled'] = $this->language->get('text_disabled');
- $data['entry_status'] = $this->language->get('entry_status');
- $data['button_save'] = $this->language->get('button_save');
- $data['button_cancel'] = $this->language->get('button_cancel');
- $data['entry_email'] = $this->language->get('entry_email');
- $data['entry_userPassword'] = $this->language->get('entry_userPassword');
- $data['entry_userDisplayName'] = $this->language->get('entry_userDisplayName');
- $data['entry_helpm'] = $this->language->get('entry_helpm');
- $data['entry_helpp'] = $this->language->get('entry_helpp');
- $data['entry_cop'] = $this->language->get('entry_cop');
- $data['entry_donate'] = $this->language->get('entry_donate');
- $data['entry_siteUrl'] = HTTPS_CATALOG;
- if (isset($this->error['jiverror'])) {
- $data['error_jiverror'] = $this->error['jiverror'];
- } else {
- $data['error_jiverror'] = '';
- }
- if (isset($this->error['warning'])) {
- $data['error_warning'] = $this->error['warning'];
- } else {
- $data['error_warning'] = '';
- }
- if (isset($this->error['email'])) {
- $data['error_email'] = $this->error['email'];
- } else {
- $data['error_email'] = '';
- }
- if (isset($this->error['userPassword'])) {
- $data['error_userPassword'] = $this->error['userPassword'];
- } else {
- $data['error_userPassword'] = '';
- }
- $data['breadcrumbs'] = array();
- $data['breadcrumbs'][] = array(
- 'text' => $this->language->get('text_home'),
- 'href' => $this->url->link('common/dashboard', 'token=' . $this->session->data['token'], 'SSL')
- );
- $data['breadcrumbs'][] = array(
- 'text' => $this->language->get('text_extension'),
- 'href' => $this->url->link('extension/module', 'token=' . $this->session->data['token'], 'SSL')
- );
- $data['breadcrumbs'][] = array(
- 'text' => $this->language->get('heading_title'),
- 'href' => $this->url->link('module/jivosite', 'token=' . $this->session->data['token'], 'SSL')
- );
- if (isset($this->request->get['loginfalse'])) {
- $data['action'] = $this->url->link('module/jivosite&loginfalse=1', 'token=' . $this->session->data['token'], 'SSL');
- }
- else{
- $data['action'] = $this->url->link('module/jivosite', 'token=' . $this->session->data['token'], 'SSL');
- }
- if (isset($this->request->get['loginfalse'])) {
- $data['cancel'] = $this->url->link('module/jivosite/inlogin', 'token=' . $this->session->data['token'], 'SSL');
- }
- else {
- $data['cancel'] = $this->url->link('extension/module', 'token=' . $this->session->data['token'], 'SSL');
- }
- if (isset($this->request->post['jivosite_partnerId'])) {
- $data['jivosite_partnerId'] = $this->request->post['jivosite_partnerId'];
- } else {
- $data['jivosite_partnerId'] = $this->config->get('jivosite_partnerId');
- }
- if (isset($this->request->post['jivosite_partnerPassword'])) {
- $data['jivosite_partnerPassword'] = $this->request->post['jivosite_partnerPassword'];
- } else {
- $data['jivosite_partnerPassword'] = $this->config->get('jivosite_partnerPassword');
- }
- if (isset($this->request->post['jivosite_siteUrl'])) {
- $data['jivosite_siteUrl'] = $this->request->post['jivosite_siteUrl'];
- } else {
- $data['jivosite_siteUrl'] = $this->config->get('jivosite_siteUrl');
- }
- if (isset($this->request->post['jivosite_email'])) {
- $data['jivosite_email'] = $this->request->post['jivosite_email'];
- } else {
- $data['jivosite_email'] = $this->config->get('jivosite_email');
- }
- if (isset($this->request->post['jivosite_userPassword'])) {
- $data['jivosite_userPassword'] = $this->request->post['jivosite_userPassword'];
- } else {
- $data['jivosite_userPassword'] = $this->config->get('jivosite_userPassword');
- }
- if (isset($this->request->post['jivosite_userDisplayName'])) {
- $data['jivosite_userDisplayName'] = $this->request->post['jivosite_userDisplayName'];
- } else {
- $data['jivosite_userDisplayName'] = $this->config->get('jivosite_userDisplayName');
- }
- if (isset($this->request->post['jivosite_authToken'])) {
- $data['jivosite_authToken'] = $this->request->post['jivosite_authToken'];
- } else {
- $data['jivosite_authToken'] = $this->config->get('jivosite_authToken');
- }
- if (isset($this->request->post['jivosite_widget_id'])) {
- $data['jivosite_widget_id'] = $this->request->post['jivosite_widget_id'];
- } else {
- $data['jivosite_widget_id'] = $this->config->get('jivosite_widget_id');
- }
- if (isset($this->request->post['jivosite_status'])) {
- $data['jivosite_status'] = $this->request->post['jivosite_status'];
- } else {
- $data['jivosite_status'] = $this->config->get('jivosite_status');
- }
- $data['header'] = $this->load->controller('common/header');
- $data['column_left'] = $this->load->controller('common/column_left');
- $data['footer'] = $this->load->controller('common/footer');
- $this->response->setOutput($this->load->view('module/jivosite.tpl', $data));
- }
- protected function validate() {
- if (!$this->user->hasPermission('modify', 'module/jivosite')) {
- $this->error['warning'] = $this->language->get('error_permission');
- }
- if (!$this->request->post['jivosite_email']) {
- $this->error['email'] = $this->language->get('error_email');
- }
- if (!$this->request->post['jivosite_userPassword']) {
- $this->error['userPassword'] = $this->language->get('error_userPassword');
- }
- return !$this->error;
- }
- public function inlogin() {
- $this->load->language('module/jivosite');
- $data['heading_title'] = $this->language->get('heading_title2');
- if (!$this->user->hasPermission('access', 'module/jivosite')) {
- $this->error['warning'] = $this->language->get('error_permission');
- }
- if (isset($this->error['warning'])) {
- $data['error_warning'] = $this->error['warning'];
- } else {
- $data['error_warning'] = '';
- }
- if (isset($this->error['jiverror'])) {
- $data['error_jiverror'] = $this->error['jiverror'];
- } else {
- $data['error_jiverror'] = '';
- }
- $data['jivlang'] = $this->config->get('config_admin_language');
- $data['text_edit'] = $this->language->get('text_edit2');
- $data['entry_cop'] = $this->language->get('entry_cop');
- $data['entry_donate'] = $this->language->get('entry_donate');
- $data['header'] = $this->load->controller('common/header');
- $data['column_left'] = $this->load->controller('common/column_left');
- $data['footer'] = $this->load->controller('common/footer');
- $data['button_nastr'] = $this->language->get('button_nastr');
- $data['button_setup'] = $this->language->get('button_setup');
- $data['button_newwind'] = $this->language->get('button_newwind');
- $data['button_newwind2'] = $this->language->get('button_newwind2');
- $data['nastr'] = $this->url->link('module/jivosite&loginfalse=1', 'token=' . $this->session->data['token'], 'SSL');
- if ($this->config->get('jivosite_authToken')) {
- $data['logintrue'] = true;
- $data['jtoken'] = $this->config->get('jivosite_authToken');
- }
- else{
- $data['logintrue'] = false;
- $data['jtoken'] = '';
- }
- $this->response->setOutput($this->load->view('module/jivosite_login.tpl', $data));
- }
- }