PageRenderTime 45ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/admin/controller/module/jivosite.php

https://bitbucket.org/melandvol/peoplesfoodbackwebsite
PHP | 309 lines | 241 code | 68 blank | 0 comment | 54 complexity | b2b81feb294dd3f510365affdb6c4ae4 MD5 | raw file
  1. <?php
  2. class ControllerModuleJivosite extends Controller {
  3. private $error = array();
  4. public function index() {
  5. $this->load->language('module/jivosite');
  6. $this->load->model('setting/setting');
  7. $this->document->setTitle($this->language->get('heading_title'));
  8. $jivlang = $this->config->get('config_admin_language');
  9. if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
  10. $query['partnerId'] = $this->request->post['jivosite_partnerId'];
  11. $query['partnerPassword'] = $this->request->post['jivosite_partnerPassword'];
  12. $query['siteUrl'] = $this->request->post['jivosite_siteUrl'];
  13. $query['email'] = $this->request->post['jivosite_email'];
  14. $query['userPassword'] = $this->request->post['jivosite_userPassword'];
  15. $query['userDisplayName'] = $this->request->post['jivosite_userDisplayName'];
  16. $authToken = md5(time().HTTPS_CATALOG);
  17. $query['authToken'] = $authToken;
  18. $query['agentId'] = 2469;
  19. $query['lang'] = $jivlang;
  20. $content = http_build_query($query);
  21. if (ini_get('allow_url_fopen')){
  22. $useCurl = false;
  23. } elseif (!extension_loaded('curl')) {
  24. if (!dl('curl.so')) {
  25. $useCurl = false;
  26. } else {
  27. $useCurl = true;
  28. }
  29. } else {
  30. $useCurl = true;
  31. }
  32. try {
  33. $path = "https://admin.jivosite.com/integration/install";
  34. if (!extension_loaded('openssl')){
  35. $path = str_replace('https:','http:',$path);
  36. }
  37. if ($useCurl){
  38. if ( $curl = curl_init() ) {
  39. curl_setopt($curl, CURLOPT_URL, $path);
  40. curl_setopt($curl, CURLOPT_RETURNTRANSFER,true);
  41. curl_setopt($curl, CURLOPT_POST, true);
  42. curl_setopt($curl, CURLOPT_POSTFIELDS, $content);
  43. $responce = curl_exec($curl);
  44. curl_close($curl);
  45. }
  46. } else {
  47. $responce = file_get_contents(
  48. $path,
  49. false,
  50. stream_context_create(
  51. array(
  52. 'http' => array(
  53. 'method' => 'POST',
  54. 'header' => 'Content-Type: application/x-www-form-urlencoded',
  55. 'content' => $content
  56. )
  57. )
  58. )
  59. );
  60. }
  61. if ($responce) {
  62. if (strstr($responce,'Error')){
  63. $this->error['jiverror'] = $responce;
  64. } else {
  65. $this->request->post['jivosite_widget_id'] = $responce;
  66. $this->request->post['jivosite_authToken'] = $authToken;
  67. $this->model_setting_setting->editSetting('jivosite', $this->request->post);
  68. $this->session->data['success'] = $this->language->get('text_success');
  69. if (isset($this->request->get['loginfalse'])) {
  70. $this->response->redirect($this->url->link('module/jivosite/inlogin', 'token=' . $this->session->data['token'], 'SSL'));
  71. }
  72. else {
  73. $this->response->redirect($this->url->link('extension/module', 'token=' . $this->session->data['token'], 'SSL'));
  74. }
  75. }
  76. }
  77. } catch (Exception $e) {
  78. _e("Connection error",'jivosite');
  79. }
  80. }
  81. $data['heading_title'] = $this->language->get('heading_title2');
  82. $data['text_edit'] = $this->language->get('text_edit');
  83. $data['text_enabled'] = $this->language->get('text_enabled');
  84. $data['text_disabled'] = $this->language->get('text_disabled');
  85. $data['entry_status'] = $this->language->get('entry_status');
  86. $data['button_save'] = $this->language->get('button_save');
  87. $data['button_cancel'] = $this->language->get('button_cancel');
  88. $data['entry_email'] = $this->language->get('entry_email');
  89. $data['entry_userPassword'] = $this->language->get('entry_userPassword');
  90. $data['entry_userDisplayName'] = $this->language->get('entry_userDisplayName');
  91. $data['entry_helpm'] = $this->language->get('entry_helpm');
  92. $data['entry_helpp'] = $this->language->get('entry_helpp');
  93. $data['entry_cop'] = $this->language->get('entry_cop');
  94. $data['entry_donate'] = $this->language->get('entry_donate');
  95. $data['entry_siteUrl'] = HTTPS_CATALOG;
  96. if (isset($this->error['jiverror'])) {
  97. $data['error_jiverror'] = $this->error['jiverror'];
  98. } else {
  99. $data['error_jiverror'] = '';
  100. }
  101. if (isset($this->error['warning'])) {
  102. $data['error_warning'] = $this->error['warning'];
  103. } else {
  104. $data['error_warning'] = '';
  105. }
  106. if (isset($this->error['email'])) {
  107. $data['error_email'] = $this->error['email'];
  108. } else {
  109. $data['error_email'] = '';
  110. }
  111. if (isset($this->error['userPassword'])) {
  112. $data['error_userPassword'] = $this->error['userPassword'];
  113. } else {
  114. $data['error_userPassword'] = '';
  115. }
  116. $data['breadcrumbs'] = array();
  117. $data['breadcrumbs'][] = array(
  118. 'text' => $this->language->get('text_home'),
  119. 'href' => $this->url->link('common/dashboard', 'token=' . $this->session->data['token'], 'SSL')
  120. );
  121. $data['breadcrumbs'][] = array(
  122. 'text' => $this->language->get('text_extension'),
  123. 'href' => $this->url->link('extension/module', 'token=' . $this->session->data['token'], 'SSL')
  124. );
  125. $data['breadcrumbs'][] = array(
  126. 'text' => $this->language->get('heading_title'),
  127. 'href' => $this->url->link('module/jivosite', 'token=' . $this->session->data['token'], 'SSL')
  128. );
  129. if (isset($this->request->get['loginfalse'])) {
  130. $data['action'] = $this->url->link('module/jivosite&loginfalse=1', 'token=' . $this->session->data['token'], 'SSL');
  131. }
  132. else{
  133. $data['action'] = $this->url->link('module/jivosite', 'token=' . $this->session->data['token'], 'SSL');
  134. }
  135. if (isset($this->request->get['loginfalse'])) {
  136. $data['cancel'] = $this->url->link('module/jivosite/inlogin', 'token=' . $this->session->data['token'], 'SSL');
  137. }
  138. else {
  139. $data['cancel'] = $this->url->link('extension/module', 'token=' . $this->session->data['token'], 'SSL');
  140. }
  141. if (isset($this->request->post['jivosite_partnerId'])) {
  142. $data['jivosite_partnerId'] = $this->request->post['jivosite_partnerId'];
  143. } else {
  144. $data['jivosite_partnerId'] = $this->config->get('jivosite_partnerId');
  145. }
  146. if (isset($this->request->post['jivosite_partnerPassword'])) {
  147. $data['jivosite_partnerPassword'] = $this->request->post['jivosite_partnerPassword'];
  148. } else {
  149. $data['jivosite_partnerPassword'] = $this->config->get('jivosite_partnerPassword');
  150. }
  151. if (isset($this->request->post['jivosite_siteUrl'])) {
  152. $data['jivosite_siteUrl'] = $this->request->post['jivosite_siteUrl'];
  153. } else {
  154. $data['jivosite_siteUrl'] = $this->config->get('jivosite_siteUrl');
  155. }
  156. if (isset($this->request->post['jivosite_email'])) {
  157. $data['jivosite_email'] = $this->request->post['jivosite_email'];
  158. } else {
  159. $data['jivosite_email'] = $this->config->get('jivosite_email');
  160. }
  161. if (isset($this->request->post['jivosite_userPassword'])) {
  162. $data['jivosite_userPassword'] = $this->request->post['jivosite_userPassword'];
  163. } else {
  164. $data['jivosite_userPassword'] = $this->config->get('jivosite_userPassword');
  165. }
  166. if (isset($this->request->post['jivosite_userDisplayName'])) {
  167. $data['jivosite_userDisplayName'] = $this->request->post['jivosite_userDisplayName'];
  168. } else {
  169. $data['jivosite_userDisplayName'] = $this->config->get('jivosite_userDisplayName');
  170. }
  171. if (isset($this->request->post['jivosite_authToken'])) {
  172. $data['jivosite_authToken'] = $this->request->post['jivosite_authToken'];
  173. } else {
  174. $data['jivosite_authToken'] = $this->config->get('jivosite_authToken');
  175. }
  176. if (isset($this->request->post['jivosite_widget_id'])) {
  177. $data['jivosite_widget_id'] = $this->request->post['jivosite_widget_id'];
  178. } else {
  179. $data['jivosite_widget_id'] = $this->config->get('jivosite_widget_id');
  180. }
  181. if (isset($this->request->post['jivosite_status'])) {
  182. $data['jivosite_status'] = $this->request->post['jivosite_status'];
  183. } else {
  184. $data['jivosite_status'] = $this->config->get('jivosite_status');
  185. }
  186. $data['header'] = $this->load->controller('common/header');
  187. $data['column_left'] = $this->load->controller('common/column_left');
  188. $data['footer'] = $this->load->controller('common/footer');
  189. $this->response->setOutput($this->load->view('module/jivosite.tpl', $data));
  190. }
  191. protected function validate() {
  192. if (!$this->user->hasPermission('modify', 'module/jivosite')) {
  193. $this->error['warning'] = $this->language->get('error_permission');
  194. }
  195. if (!$this->request->post['jivosite_email']) {
  196. $this->error['email'] = $this->language->get('error_email');
  197. }
  198. if (!$this->request->post['jivosite_userPassword']) {
  199. $this->error['userPassword'] = $this->language->get('error_userPassword');
  200. }
  201. return !$this->error;
  202. }
  203. public function inlogin() {
  204. $this->load->language('module/jivosite');
  205. $data['heading_title'] = $this->language->get('heading_title2');
  206. if (!$this->user->hasPermission('access', 'module/jivosite')) {
  207. $this->error['warning'] = $this->language->get('error_permission');
  208. }
  209. if (isset($this->error['warning'])) {
  210. $data['error_warning'] = $this->error['warning'];
  211. } else {
  212. $data['error_warning'] = '';
  213. }
  214. if (isset($this->error['jiverror'])) {
  215. $data['error_jiverror'] = $this->error['jiverror'];
  216. } else {
  217. $data['error_jiverror'] = '';
  218. }
  219. $data['jivlang'] = $this->config->get('config_admin_language');
  220. $data['text_edit'] = $this->language->get('text_edit2');
  221. $data['entry_cop'] = $this->language->get('entry_cop');
  222. $data['entry_donate'] = $this->language->get('entry_donate');
  223. $data['header'] = $this->load->controller('common/header');
  224. $data['column_left'] = $this->load->controller('common/column_left');
  225. $data['footer'] = $this->load->controller('common/footer');
  226. $data['button_nastr'] = $this->language->get('button_nastr');
  227. $data['button_setup'] = $this->language->get('button_setup');
  228. $data['button_newwind'] = $this->language->get('button_newwind');
  229. $data['button_newwind2'] = $this->language->get('button_newwind2');
  230. $data['nastr'] = $this->url->link('module/jivosite&loginfalse=1', 'token=' . $this->session->data['token'], 'SSL');
  231. if ($this->config->get('jivosite_authToken')) {
  232. $data['logintrue'] = true;
  233. $data['jtoken'] = $this->config->get('jivosite_authToken');
  234. }
  235. else{
  236. $data['logintrue'] = false;
  237. $data['jtoken'] = '';
  238. }
  239. $this->response->setOutput($this->load->view('module/jivosite_login.tpl', $data));
  240. }
  241. }