File indexing completed on 2024-05-12 05:58:38

0001 <?php
0002 
0003 /**
0004  *  ocs-webserver
0005  *
0006  *  Copyright 2016 by pling GmbH.
0007  *
0008  *    This file is part of ocs-webserver.
0009  *
0010  *    This program is free software: you can redistribute it and/or modify
0011  *    it under the terms of the GNU Affero General Public License as
0012  *    published by the Free Software Foundation, either version 3 of the
0013  *    License, or (at your option) any later version.
0014  *
0015  *    This program is distributed in the hope that it will be useful,
0016  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
0017  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0018  *    GNU Affero General Public License for more details.
0019  *
0020  *    You should have received a copy of the GNU Affero General Public License
0021  *    along with this program.  If not, see <http://www.gnu.org/licenses/>.
0022  **/
0023 class MembersettingController extends Zend_Controller_Action
0024 {
0025 
0026     const GROUP_METAHEADER = 1;
0027     protected $_format = 'json';
0028 
0029     public function init()
0030     {
0031         parent::init();
0032         $this->initView();
0033         // $this->_initResponseHeader();
0034     }
0035 
0036     public function initView()
0037     {
0038         // Disable render view
0039         $this->_helper->layout->disableLayout();
0040         $this->_helper->viewRenderer->setNoRender(true);
0041     }
0042 
0043     public function indexAction()
0044     {
0045         $this->_sendErrorResponse(999, 'unknown request');
0046     }
0047 
0048     public function getsettingsAction()
0049     {
0050         $this->_initResponseHeader();
0051         $identity = Zend_Auth::getInstance()->getStorage()->read();
0052         if ($identity == null || $identity->member_id == null) {
0053             $response = array(
0054                 'status' => 'error',
0055                 'msg'    => 'no user found'
0056             );
0057             $this->_sendResponse($response, $this->_format);
0058 
0059             return;
0060         }
0061         $model = new Default_Model_MemberSettingValue();
0062         $member_id = $identity->member_id;
0063 
0064         $results = $model->findMemberSettings($member_id, $this::GROUP_METAHEADER);
0065         $response = array(
0066             'status'    => 'ok',
0067             'member_id' => $member_id,
0068             'results'   => $results
0069         );
0070         $this->_sendResponse($response, $this->_format);
0071     }
0072 
0073     protected function _initResponseHeader()
0074     {
0075         http_response_code(200);
0076 
0077         if (!empty($_SERVER['HTTP_ORIGIN'])) {
0078             header('Access-Control-Allow-Origin: ' . $_SERVER['HTTP_ORIGIN'], true);
0079             header('Access-Control-Allow-Credentials: true', true);
0080             header('Access-Control-Max-Age: 1728000', true);
0081         }
0082 
0083 
0084         if (!empty($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_METHOD'])) {
0085             header('Access-Control-Allow-Methods: ' . implode(', ', array_unique([
0086                     'OPTIONS',
0087                     'HEAD',
0088                     'GET',
0089                     'POST',
0090                     'PUT',
0091                     strtoupper($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_METHOD'])
0092                 ])), true);
0093         }
0094 
0095         if (!empty($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS'])) {
0096             header('Access-Control-Allow-Headers: ' . $_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS'], true);
0097             header('Access-Control-Expose-Headers: Authorization, Content-Type, Accept', true);
0098         }
0099 
0100         if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') {
0101             exit;
0102         }
0103 
0104         header('Content-Type: application/json; charset=UTF-8', true);
0105 
0106     }
0107 
0108     /*public function getsettingsAction()
0109     {
0110         $this->_helper->layout->disableLayout();
0111     }*/
0112 
0113     protected function _sendResponse($response, $format = 'json', $xmlRootTag = 'ocs')
0114     {
0115         header('Content-Type: application/json; charset=UTF-8');
0116         echo json_encode($response);
0117     }
0118 
0119     public function setsettingsAction()
0120     {
0121         $this->_initResponseHeader();
0122         $identity = Zend_Auth::getInstance()->getStorage()->read();
0123         if ($identity == null || $identity->member_id == null) {
0124             $response = array(
0125                 'status' => 'error',
0126                 'msg'    => 'no user found'
0127             );
0128         } else {
0129             $model = new Default_Model_MemberSettingValue();
0130             $member_id = $identity->member_id;
0131             $member_setting_item_id = $this->getParam('itemid');
0132             $value = $this->getParam('itemvalue');
0133             $model->updateOrInsertSetting($member_id, $member_setting_item_id, null, $value);
0134             $response = array(
0135                 'status' => 'ok'
0136             );
0137         }
0138         $this->_sendResponse($response, $this->_format);
0139     }
0140 
0141     public function notificationAction()
0142     {
0143         $this->_initResponseHeader();
0144         $identity = Zend_Auth::getInstance()->getStorage()->read();
0145         if ($identity == null || $identity->member_id == null) {
0146             $response = array(
0147                 'status' => 'error',
0148                 'msg'    => 'no user found'
0149             );
0150             $this->_sendResponse($response, $this->_format);
0151 
0152             return;
0153         }
0154         $modelForum = new Default_Model_Ocs_Forum();
0155         $data = $modelForum->getUserNotifications($identity->member_id);
0156         $results = $data;
0157 
0158         $this->_sendResponse($results, $this->_format);
0159 
0160     }
0161 
0162     // public function anonymousdlAction()
0163     // {
0164     //
0165     //     $this->_initResponseHeader();
0166     //     $identity = Zend_Auth::getInstance()->getStorage()->read();
0167     //     if($identity==null)
0168     //     {
0169     //         $config = Zend_Registry::get('config');
0170     //         $cookieName = $config->settings->session->auth->anonymous;
0171     //         $storedInCookie = isset($_COOKIE[$cookieName]) ? $_COOKIE[$cookieName] : NULL;
0172     //         if($storedInCookie)
0173     //         {
0174     //             $memberDlAnonymous = new Default_Model_DbTable_MemberDownloadAnonymous();
0175     //             $dls = $memberDlAnonymous->countDownloads($storedInCookie);
0176     //
0177     //             $response = array(
0178     //             'status'     => 'ok',
0179     //             'dls'    => $dls
0180     //             );
0181     //             $this->_sendResponse($response, $this->_format);
0182     //             return;
0183     //         }
0184     //
0185     //     }
0186     //
0187     //     $response = array(
0188     //         'status'     => 'ok',
0189     //         'dls'    => 0
0190     //         );
0191     //     $this->_sendResponse($response, $this->_format);
0192     //
0193     // }
0194 
0195     public function memberjsonAction()
0196     {
0197         $this->_initResponseHeader();
0198         $identity = Zend_Auth::getInstance()->getStorage()->read();
0199         $member_id = $this->getParam('member_id');
0200         $results = null;
0201         if ($member_id) {
0202             $info = new Default_Model_Info();
0203             $commentsOpendeskop = $info->getDiscussionOpendeskop($member_id);
0204             $results = array('commentsOpendeskop' => $commentsOpendeskop);
0205         }
0206         $this->_sendResponse($results, $this->_format);
0207     }
0208 
0209     public function searchmemberAction()
0210     {
0211         $this->_initResponseHeader();
0212         $username = $this->getParam('username');
0213         $results = null;
0214         if (strlen(trim($username)) > 2) {
0215             $username = str_replace("_", "\_", $username);
0216             $model = new Default_Model_Member();
0217             $results = $model->findActiveMemberByName($username);
0218             $helperImage = new Default_View_Helper_Image();
0219             foreach ($results as &$value) {
0220                 $avatar = $helperImage->image($value['profile_image_url'],
0221                     array('width' => 100, 'height' => 100, 'crop' => 2));
0222                 $value['profile_image_url'] = $avatar;
0223             }
0224         }
0225         $this->_sendResponse($results, $this->_format);
0226     }
0227 
0228    
0229     public function userinfoAction()
0230     {
0231         $this->_initResponseHeader();
0232         $member_id = $this->getParam('member_id');
0233         $info = new Default_Model_Info();
0234         $data = $info->getTooptipForMember($member_id);
0235         $this->_sendResponse($data, $this->_format);
0236     }
0237 
0238 }