Beispiel #1
0
 /**
  * Class constructor
  */
 public function __construct(BASE_CLASS_WidgetParameter $paramObj)
 {
     parent::__construct();
     $this->creditsService = USERCREDITS_BOL_CreditsService::getInstance();
     $userId = OW::getUser()->getId();
     if (!$userId) {
         $this->setVisible(false);
         return;
     }
     $balance = $this->creditsService->getCreditsBalance($userId);
     $this->assign('balance', $balance);
     $this->setSettingValue(self::SETTING_TOOLBAR, array(array('label' => OW::getLanguage()->text('usercredits', 'get_credits'), 'href' => OW::getRouter()->urlForRoute('usercredits.buy_credits'))));
 }
Beispiel #2
0
 public function __construct()
 {
     parent::__construct();
     if (!OW::getUser()->isAuthenticated()) {
         throw new Redirect403Exception();
     }
     $service = HOTLIST_BOL_Service::getInstance();
     if ($service->findUserById(OW::getUser()->getId())) {
         $this->assign('userInList', true);
         $this->assign('text_notification', OW::getLanguage()->text('hotlist', 'text_remove_from_list'));
         $removeFromListForm = new RemoveFromHotListForm();
         $this->addForm($removeFromListForm);
     } else {
         $this->assign('userInList', false);
         if (OW::getPluginManager()->isPluginActive('usercredits')) {
             $creditService = USERCREDITS_BOL_CreditsService::getInstance();
             $action = $creditService->findAction('hotlist', 'add_to_list');
             $actionPrice = $creditService->findActionPriceForUser($action->id, OW::getUser()->getId());
             $amount = $actionPrice->amount;
         } else {
             $userCreditsAction = new HOTLIST_CLASS_Credits();
             $amount = $userCreditsAction->getActionCost();
         }
         $status = BOL_AuthorizationService::getInstance()->getActionStatus('hotlist', 'add_to_list');
         if (isset($status['authorizedBy']) && $status['authorizedBy'] == 'base') {
             $this->assign('floatbox_text', OW::getLanguage()->text('hotlist', 'floatbox_text_simple'));
         } else {
             $this->assign('floatbox_text', OW::getLanguage()->text('hotlist', 'floatbox_text', array('amount' => abs($amount))));
         }
         $addToListForm = new AddToHotListForm();
         $this->addForm($addToListForm);
     }
 }
Beispiel #3
0
 public function grantCredits()
 {
     if (!OW::getRequest()->isAjax()) {
         throw new Redirect404Exception();
     }
     if (!OW::getUser()->isAuthenticated()) {
         throw new AuthenticateException();
     }
     $form = new USERCREDITS_CLASS_GrantCreditsForm();
     if ($form->isValid($_POST)) {
         $lang = OW::getLanguage();
         $creditService = USERCREDITS_BOL_CreditsService::getInstance();
         $grantorId = OW::getUser()->getId();
         $values = $form->getValues();
         $userId = (int) $values['userId'];
         $amount = abs((int) $values['amount']);
         $granted = $creditService->grantCredits($grantorId, $userId, $amount);
         $credits = $creditService->getCreditsBalance($grantorId);
         if ($granted) {
             $data = array('amount' => $amount, 'grantorId' => $grantorId, 'userId' => $userId);
             $event = new OW_Event('usercredits.grant', $data);
             OW::getEventManager()->trigger($event);
             $data = array('message' => $lang->text('usercredits', 'credits_granted', array('amount' => $amount)), 'credits' => $credits);
         } else {
             $data = array('error' => $lang->text('usercredits', 'credits_grant_error'));
         }
         exit(json_encode($data));
     }
 }
 /**
  * Returns class instance
  *
  * @return USERCREDITS_BOL_CreditsService
  */
 public static function getInstance()
 {
     if (null === self::$classInstance) {
         self::$classInstance = new self();
     }
     return self::$classInstance;
 }
Beispiel #5
0
 public function __construct()
 {
     parent::__construct();
     $creditService = USERCREDITS_BOL_CreditsService::getInstance();
     $accountTypeId = $creditService->getUserAccountTypeId(OW::getUser()->getId());
     $earning = $creditService->findCreditsActions('earn', $accountTypeId, false);
     $this->assign('earning', $earning);
 }
Beispiel #6
0
function credits_add_console_dashboard_item(BASE_EventCollector $e)
{
    if (!OW::getUser()->isAuthenticated()) {
        return;
    }
    $userId = OW::getUser()->getId();
    $credits = USERCREDITS_BOL_CreditsService::getInstance()->getCreditsBalance($userId);
    $e->add(array(BASE_CMP_Console::DATA_KEY_URL => OW::getRouter()->urlForRoute('credits_logs', array('type' => 'all')), BASE_CMP_Console::DATA_KEY_ICON_CLASS => 'ow_ic_lens', BASE_CMP_Console::DATA_KEY_TITLE => OW::getLanguage()->text('credits', 'action_label', array('credits' => $credits)), BASE_CMP_Console::DATA_KEY_ITEMS_LABEL => OW::getLanguage()->text('credits', 'action_label', array('credits' => $credits)), BASE_CMP_Console::DATA_KEY_BLOCK => true));
}
Beispiel #7
0
 public function __construct($page, $limit)
 {
     parent::__construct();
     if (!OW::getUser()->isAuthenticated()) {
         $this->setVisible(false);
     }
     $userId = OW::getUser()->getId();
     $creditService = USERCREDITS_BOL_CreditsService::getInstance();
     $history = $creditService->getUserLogHistory($userId, $page, $limit);
     $this->assign('history', $history);
 }
Beispiel #8
0
 public function __construct($userId)
 {
     parent::__construct();
     if (!OW::getUser()->isAuthenticated()) {
         $this->setVisible(false);
     }
     $creditService = USERCREDITS_BOL_CreditsService::getInstance();
     $amount = $creditService->getGrantableAmountForUser(OW::getUser()->getId());
     $form = new USERCREDITS_CLASS_GrantCreditsForm();
     $form->getElement('userId')->setValue($userId);
     $form->getElement('amount')->setValue($amount);
     $this->addForm($form);
 }
 /**
  * Class constructor
  */
 public function __construct(BASE_CLASS_WidgetParameter $paramObj)
 {
     parent::__construct();
     $this->creditsService = USERCREDITS_BOL_CreditsService::getInstance();
     $userId = OW::getUser()->getId();
     $lang = OW::getLanguage();
     if (!$userId) {
         $this->setVisible(false);
         return;
     }
     $balance = $this->creditsService->getCreditsBalance($userId);
     $this->assign('balance', $balance);
     $this->setSettingValue(self::SETTING_TOOLBAR, array(array('label' => $lang->text('usercredits', 'buy_more'), 'href' => OW::getRouter()->urlForRoute('usercredits.buy_credits'))));
     $accountTypeId = $this->creditsService->getUserAccountTypeId($userId);
     $earning = (bool) $this->creditsService->findCreditsActions('earn', $accountTypeId);
     $this->assign('showEarning', $earning);
     $script = '';
     if ($earning) {
         $script .= '$("#credits-link-earn").click(function(){
             document.creditsEarnFloatbox = OW.ajaxFloatBox(
                 "USERCREDITS_CMP_Earn", {}, { width : 432, title: ' . json_encode($lang->text('usercredits', 'earn_credits')) . '}
             );
         });
         ';
     }
     $history = (bool) $this->creditsService->countUserLogEntries($userId);
     $this->assign('showHistory', $history);
     if ($history) {
         $script .= '$("#credits-link-history").click(function(){
             document.creditsHistoryFloatbox = OW.ajaxFloatBox(
                 "USERCREDITS_CMP_History", {}, { width : 500, title: ' . json_encode($lang->text('usercredits', 'history')) . '}
             );
         });
         ';
     }
     if (mb_strlen($script)) {
         OW::getDocument()->addOnloadScript($script);
     }
 }
Beispiel #10
0
 public function onCreditsUpdateActionDisabledStatus(OW_Event $e)
 {
     $params = $e->getParams();
     if ($params['pluginKey'] == 'virtualgifts' && $params['actionKey'] == 'send_virtual_gift') {
         $giftService = VIRTUALGIFTS_BOL_VirtualGiftsService::getInstance();
         $creditService = USERCREDITS_BOL_CreditsService::getInstance();
         $templates = $giftService->getTemplateList();
         foreach ($templates as $tpl) {
             $event = new BASE_CLASS_EventCollector('usercredits.action_update');
             $event->add(array('pluginKey' => 'virtualgifts', 'action' => 'template_' . $tpl['id'], 'amount' => $tpl['price'] == 0 ? 0 : -$tpl['price'], 'hidden' => 1, 'disabled' => (int) $params['disabled']));
             OW::getEventManager()->trigger($event);
         }
     }
 }
 public function deliverSale(BOL_BillingSale $sale)
 {
     $packId = $sale->entityId;
     $creditsService = USERCREDITS_BOL_CreditsService::getInstance();
     $pack = $creditsService->findPackById($packId);
     if (!$pack) {
         return false;
     }
     if ($creditsService->increaseBalance($sale->userId, $pack->credits)) {
         $creditsService->logAction(0, $sale->userId, $pack->credits);
         return true;
     }
     return false;
 }
Beispiel #12
0
 public function __construct($userId)
 {
     parent::__construct();
     if (!OW::getUser()->isAuthorized('usercredits')) {
         $this->setVisible(false);
     }
     $creditService = USERCREDITS_BOL_CreditsService::getInstance();
     $balance = $creditService->getCreditsBalance($userId);
     $form = new USERCREDITS_CLASS_SetCreditsForm();
     $form->getElement('userId')->setValue($userId);
     $form->getElement('balance')->setValue($balance);
     $this->addForm($form);
     $this->assign('balance', $balance);
 }
Beispiel #13
0
 public function __construct()
 {
     parent::__construct();
     if (!OW::getUser()->isAuthenticated()) {
         $this->setVisible(false);
     }
     $lang = OW::getLanguage();
     $this->addComponent('items', new USERCREDITS_CMP_HistoryItems(1, self::HISTORY_DISPLAY_ENTRY_LIMIT));
     $userId = OW::getUser()->getId();
     $loadMore = USERCREDITS_BOL_CreditsService::getInstance()->countUserLogEntries($userId) > self::HISTORY_DISPLAY_ENTRY_LIMIT;
     $this->assign('loadMore', $loadMore);
     $toolbar = array();
     if ($loadMore) {
         $toolbar = array(array('label' => $lang->text('usercredits', 'view_more'), 'href' => OW::getRouter()->urlForRoute('usercredits.history')));
     }
     $this->assign('toolbar', $toolbar);
 }
 public function deliverSale(BOL_BillingSale $sale)
 {
     $packId = $sale->entityId;
     $creditsService = USERCREDITS_BOL_CreditsService::getInstance();
     $pack = $creditsService->findPackById($packId);
     if (!$pack) {
         return false;
     }
     if ($creditsService->increaseBalance($sale->userId, $pack->credits)) {
         $creditsService->sendPackPurchasedNotification($sale->userId, $pack->credits, $sale->totalAmount);
         $actionDto = USERCREDITS_BOL_CreditsService::getInstance()->findAction('usercredits', 'buy_credits');
         if (!empty($actionDto) && !empty($actionDto->id)) {
             $creditsService->logAction($actionDto->id, $sale->userId, $pack->credits);
         }
         return true;
     }
     return false;
 }
Beispiel #15
0
 public function history()
 {
     if (!OW::getUser()->isAuthenticated()) {
         throw new AuthenticateException();
     }
     $creditService = USERCREDITS_BOL_CreditsService::getInstance();
     $lang = OW::getLanguage();
     $page = !empty($_GET['page']) && (int) $_GET['page'] ? abs((int) $_GET['page']) : 1;
     $limit = 20;
     $this->addComponent('items', new USERCREDITS_CMP_HistoryItems($page, $limit));
     $records = $creditService->countUserLogEntries(OW::getUser()->getId());
     // Paging
     $pages = (int) ceil($records / $limit);
     $paging = new BASE_CMP_Paging($page, $pages, 10);
     $this->assign('paging', $paging->render());
     $this->setPageHeading($lang->text('usercredits', 'credits_history_page_heading'));
     OW::getDocument()->setTitle($lang->text('usercredits', 'credits_history_page_heading'));
     OW::getNavigation()->activateMenuItem(OW_Navigation::MAIN, 'base', 'dashboard');
 }
Beispiel #16
0
 public function collectItems(BASE_CLASS_ConsoleItemCollector $event)
 {
     $language = OW::getLanguage();
     $router = OW::getRouter();
     if (OW::getUser()->isAuthenticated()) {
         $userId = OW::getUser()->getId();
         $credits = USERCREDITS_BOL_CreditsService::getInstance()->getCreditsBalance($userId);
         $item = new BASE_CMP_ConsoleDropdownMenu($language->text('credits', 'action_label', array('credits' => $credits)));
         $item->setUrl($router->urlForRoute('base_user_profile', array('username' => OW::getUser()->getUserObject()->getUsername())));
         if (OW::getUser()->isAdmin() || OW::getUser()->isAuthorized('credits')) {
             $item->addItem('main', array('label' => $language->text('credits', 'view_admin_logs'), 'url' => $router->urlForRoute('credits_admin_logs')));
         }
         $item->addItem('main', array('label' => $language->text('credits', 'my_credit_log'), 'url' => $router->urlForRoute('credits_logs', array('type' => 'all'))));
         $item->addItem('main', array('label' => $language->text('credits', 'send_credits'), 'url' => $router->urlForRoute('credits_transfer')));
         $item->addItem('main', array('label' => $language->text('credits', 'buy_credits'), 'url' => $router->urlForRoute('usercredits.buy_credits')));
         $addItemsEvent = new BASE_CLASS_EventCollector('base.add_main_console_item');
         OW::getEventManager()->trigger($addItemsEvent);
         $event->addItem($item, 7);
     }
 }
 public function onCollectButtons(BASE_CLASS_EventCollector $event)
 {
     $params = $event->getParams();
     if ($params["entityType"] != HINT_BOL_Service::ENTITY_TYPE_USER) {
         return;
     }
     $userId = $params["entityId"];
     if (!OW::getUser()->isAuthenticated()) {
         return;
     }
     $uniqId = uniqid("hint-uc-");
     $creditsService = USERCREDITS_BOL_CreditsService::getInstance();
     $balance = $creditsService->getCreditsBalance($userId);
     $fbParams = array($userId, false);
     $fbSettings = array("width" => 300, "title" => null);
     $showButton = false;
     $js = UTIL_JsGenerator::newInstance();
     if (OW::getUser()->isAuthorized('usercredits')) {
         $fbSettings["title"] = OW::getLanguage()->text('usercredits', 'profile_toolbar_item_credits', array('credits' => $balance));
         $js->jQueryEvent("#" . $uniqId, "click", 'var self = $(this); OW.ajaxFloatBox("USERCREDITS_CMP_SetCredits", e.data.params , $.extend({}, e.data.settings, {scope: { btn: $(this), callBack: function(r) {
                 if (r.text) self.text(r.text);
              }}}));', array('e'), array("params" => $fbParams, "settings" => $fbSettings));
         $showButton = true;
     } else {
         if ($userId == OW::getUser()->getId()) {
             return;
         }
         $grantorBalance = $creditsService->getCreditsBalance(OW::getUser()->getId());
         if ($grantorBalance) {
             $fbSettings["title"] = OW::getLanguage()->text('usercredits', 'profile_toolbar_grant');
             $fbSettings["width"] = 400;
             $js->jQueryEvent("#" . $uniqId, "click", 'OW.ajaxFloatBox("USERCREDITS_CMP_GrantCredits", e.data.params , e.data.settings);', array('e'), array("params" => $fbParams, "settings" => $fbSettings));
             $showButton = true;
         }
     }
     if ($showButton) {
         OW::getDocument()->addOnloadScript($js);
         $button = array("key" => "usercredits", "label" => $fbSettings["title"], "attrs" => array("id" => $uniqId));
         $event->add($button);
     }
 }
Beispiel #18
0
 public function __construct()
 {
     parent::__construct('buy-credits-form');
     $packs = USERCREDITS_BOL_CreditsService::getInstance()->getPackList();
     $packField = new RadioField('pack');
     $packField->setRequired();
     $value = 0;
     foreach ($packs as $p) {
         $packField->addOption($p['id'], $p['title']);
         if ($value == 0) {
             $value = $p['id'];
         }
     }
     $packField->setValue($value);
     $this->addElement($packField);
     $gatewaysField = new BillingGatewaySelectionField('gateway');
     $gatewaysField->setRequired(true);
     $this->addElement($gatewaysField);
     $submit = new Submit('buy');
     $submit->setValue(OW::getLanguage()->text('base', 'checkout'));
     $this->addElement($submit);
 }
Beispiel #19
0
 public function findProductByItunesProductId($productId)
 {
     $entityKey = strtolower(substr($productId, 0, strrpos($productId, '_')));
     $entityId = (int) substr($productId, strrpos($productId, '_') + 1);
     if (!strlen($entityKey) || !$productId) {
         return null;
     }
     $pm = OW::getPluginManager();
     $return = array();
     switch ($entityKey) {
         case 'membership_plan':
             if (!$pm->isPluginActive('membership')) {
                 return null;
             }
             $membershipService = MEMBERSHIP_BOL_MembershipService::getInstance();
             $plan = $membershipService->findPlanById($entityId);
             if (!$plan) {
                 return null;
             }
             $return['pluginKey'] = 'membership';
             $return['entityDescription'] = $membershipService->getFormattedPlan($plan->price, $plan->period, $plan->recurring);
             $return['price'] = floatval($plan->price);
             $return['period'] = $plan->period;
             $return['recurring'] = $plan->recurring;
             break;
         case 'user_credits_pack':
             if (!$pm->isPluginActive('usercredits')) {
                 return null;
             }
             $creditsService = USERCREDITS_BOL_CreditsService::getInstance();
             $pack = $creditsService->findPackById($entityId);
             if (!$pack) {
                 return null;
             }
             $return['pluginKey'] = 'usercredits';
             $return['entityDescription'] = $creditsService->getPackTitle($pack->price, $pack->credits);
             $return['price'] = floatval($pack->price);
             $return['period'] = 30;
             $return['recurring'] = 0;
             break;
     }
     $return['entityKey'] = $entityKey;
     $return['entityId'] = $entityId;
     return $return;
 }
Beispiel #20
0
 public function onCollectBillingGatewayProduct(BASE_CLASS_EventCollector $event)
 {
     $service = USERCREDITS_BOL_CreditsService::getInstance();
     $packs = $service->getPackList();
     if (!$packs) {
         return;
     }
     $data = array();
     foreach ($packs as $pack) {
         $data[] = array('pluginKey' => 'usercredits', 'label' => $pack['title'], 'entityType' => 'user_credits_pack', 'entityId' => $pack['id']);
     }
     $event->add($data);
 }
Beispiel #21
0
 public function buybycredits()
 {
     $billingService = BOL_BillingService::getInstance();
     if (!isset($_POST['amount'])) {
         $this->redirect($billingService->getOrderFailedPageUrl());
     }
     $userId = OW::getUser()->getId();
     $itemName = $_POST['itemName'];
     $amount = (double) $_POST['amount'];
     $currency = $_POST['currency'];
     $availableCredits = USERCREDITS_BOL_CreditsService::getInstance()->getCreditsBalance($userId);
     $creditValue = $billingService->getGatewayConfigValue('billingcredits', 'creditValue');
     $totalCreditsRequired = round($amount * $creditValue);
     if ($availableCredits < $totalCreditsRequired) {
         $this->assign('formUrl', $billingService->getOrderCancelledPageUrl());
     } else {
         $this->assign('formUrl', OW::getRouter()->urlFor('BILLINGCREDITS_CTRL_Order', 'purchase'));
     }
     $this->assign('itemName', $itemName);
     $this->assign('amount', $amount);
     $this->assign('currency', $currency);
     $this->assign('availableCredits', $availableCredits);
     $this->assign('totalCreditsRequired', $totalCreditsRequired);
     $this->assign('buyingUser', $userId);
     $this->assign('custom', $_POST['custom']);
     $this->assign('transId', $_POST['transId']);
 }
Beispiel #22
0
 private function getSuggestedCreditsPack($userId, $pluginKey, $actionKey)
 {
     $creditsService = USERCREDITS_BOL_CreditsService::getInstance();
     $params = array();
     $params['groupName'] = $pluginKey;
     $params['actionName'] = $actionKey;
     $params['userId'] = $userId;
     $actionEvent = new OW_Event('usercredits.get_action_key', $params);
     OW::getEventManager()->trigger($actionEvent);
     $data = $actionEvent->getData();
     $actionName = !empty($data) ? $data : $actionKey;
     $action = $creditsService->findAction($pluginKey, $actionName);
     if (!$action) {
         return null;
     }
     // get user account type
     $accTypeName = BOL_UserService::getInstance()->findUserById($userId)->getAccountType();
     $accType = BOL_QuestionService::getInstance()->findAccountTypeByName($accTypeName);
     $packs = $creditsService->getPackList($accType->id);
     if (!$packs) {
         return null;
     }
     $actionPrice = $creditsService->findActionPrice($action->id, $accType->id);
     if (!$actionPrice) {
         return null;
     }
     $balance = $creditsService->getCreditsBalance($userId);
     $suggestedPack = array();
     foreach ($packs as $pack) {
         if ($pack['price'] + $balance >= $actionPrice->amount && !$actionPrice->disabled) {
             $suggestedPack = $pack;
             break;
         }
     }
     return $suggestedPack;
 }
Beispiel #23
0
 public function registerPayout()
 {
     if (!OW::getRequest()->isAjax()) {
         exit(json_encode(array('result' => false)));
     }
     $service = OCSAFFILIATES_BOL_Service::getInstance();
     $lang = OW::getLanguage();
     $form = new OCSAFFILIATES_CLASS_RegisterPayoutForm('register_payout');
     if (!$form->isValid($_POST)) {
         exit(json_encode(array('result' => false, 'error' => $lang->text('ocsaffiliates', 'fill_required_fields'))));
     }
     $values = $form->getValues();
     $affiliateId = (int) $values['affiliateId'];
     $affiliate = $service->findAffiliateById($affiliateId);
     if (!$affiliate) {
         exit(json_encode(array('result' => false)));
     }
     if (!OW::getUser()->isAdmin()) {
         exit(json_encode(array('result' => false)));
     }
     $payout = new OCSAFFILIATES_BOL_Payout();
     $payout->affiliateId = $affiliateId;
     $payout->amount = abs(floatval($values['amount']));
     $payout->paymentDate = time();
     $payout->method = 'currency';
     if ($values['byCredits']) {
         $assoc = OCSAFFILIATES_BOL_Service::getInstance()->getAffiliateAssocUser($affiliateId);
         if (OW::getPluginManager()->isPluginActive('usercredits') && $assoc) {
             $payout->method = 'credits';
             USERCREDITS_BOL_CreditsService::getInstance()->increaseBalance($assoc['id'], $payout->amount);
         }
     }
     $service->registerPayout($payout);
     OW::getFeedback()->info($lang->text('ocsaffiliates', 'payout_registered'));
     exit(json_encode(array('result' => true)));
 }
Beispiel #24
0
 private function getSuggestedCreditsPack($userId, $pluginKey, $actionKey)
 {
     $creditsService = USERCREDITS_BOL_CreditsService::getInstance();
     $action = $creditsService->findAction($pluginKey, $actionKey);
     if (!$action) {
         return null;
     }
     // get user account type
     $accTypeName = BOL_UserService::getInstance()->findUserById($userId)->getAccountType();
     $accType = BOL_QuestionService::getInstance()->findAccountTypeByName($accTypeName);
     $packs = $creditsService->getPackList($accType->id);
     if (!$packs) {
         return null;
     }
     $actionPrice = $creditsService->findActionPrice($action->id, $accType->id);
     if (!$actionPrice) {
         return null;
     }
     $balance = $creditsService->getCreditsBalance($userId);
     $suggestedPack = array();
     foreach ($packs as $pack) {
         if ($pack['price'] + $balance >= $actionPrice->amount && !$actionPrice->disabled) {
             $suggestedPack = $pack;
             break;
         }
     }
     return $suggestedPack;
 }
Beispiel #25
0
 /**
  * Updates forum plugin configuration
  *
  * @return boolean
  */
 public function process()
 {
     $values = $this->getValues();
     $enableAttachmentsValue = empty($values['enableAttachments']) ? false : (bool) $values['enableAttachments'];
     $config = OW::getConfig();
     $enableAttachmentsValue = true;
     //TODO tmp solution, remove this assignment when it will be necessary
     $config->saveConfig('mailbox', 'enable_attachments', $enableAttachmentsValue);
     $config->saveConfig('mailbox', 'show_all_members', 0);
     $send_message_interval = empty($values['send_message_interval']) ? 0 : (int) $values['send_message_interval'];
     $config->saveConfig('mailbox', 'send_message_interval', $send_message_interval);
     $authorization = OW::getAuthorization();
     $groupName = 'mailbox';
     $authorization->deleteAction($groupName, 'read_message');
     $authorization->deleteAction($groupName, 'send_message');
     $authorization->deleteAction($groupName, 'reply_to_message');
     $authorization->deleteAction($groupName, 'read_chat_message');
     $authorization->deleteAction($groupName, 'send_chat_message');
     $authorization->deleteAction($groupName, 'reply_to_chat_message');
     switch ($values['active_mode_list']) {
         case 'chat':
             $modes = array($values['active_mode_list']);
             $config->saveConfig('mailbox', 'active_modes', json_encode($modes));
             $authorization->addAction($groupName, 'read_chat_message');
             $authorization->addAction($groupName, 'send_chat_message');
             $authorization->addAction($groupName, 'reply_to_chat_message');
             break;
         case 'mail':
             $modes = array($values['active_mode_list']);
             $config->saveConfig('mailbox', 'active_modes', json_encode($modes));
             $authorization->addAction($groupName, 'read_message');
             $authorization->addAction($groupName, 'send_message');
             $authorization->addAction($groupName, 'reply_to_message');
             break;
         case 'mailchat':
             $modes = array('mail', 'chat');
             $config->saveConfig('mailbox', 'active_modes', json_encode($modes));
             $authorization->addAction($groupName, 'read_message');
             $authorization->addAction($groupName, 'send_message');
             $authorization->addAction($groupName, 'reply_to_message');
             $authorization->addAction($groupName, 'read_chat_message');
             $authorization->addAction($groupName, 'send_chat_message');
             $authorization->addAction($groupName, 'reply_to_chat_message');
             break;
     }
     if ($values['active_mode_list'] != 'mail') {
         $show_all_members = empty($values['show_all_members']) ? 0 : 1;
         $config->saveConfig('mailbox', 'show_all_members', $show_all_members);
     }
     if (OW::getPluginManager()->isPluginActive('usercredits')) {
         USERCREDITS_BOL_CreditsService::getInstance()->deleteActionsByPluginKey('mailbox');
         $credits = new MAILBOX_CLASS_Credits();
         $credits->triggerCreditActionsAdd();
     }
     return array('result' => true);
 }
 /**
  * @param MAILBOX_BOL_Message $message
  * @return array
  */
 public function getMessageDataForApi($message)
 {
     $defaultAvatarUrl = BOL_AvatarService::getInstance()->getDefaultAvatarUrl();
     $item = array();
     $item['convId'] = (int) $message->conversationId;
     $item['mode'] = $this->getConversationMode((int) $message->conversationId);
     $item['id'] = (int) $message->id;
     $item['date'] = date('Y-m-d', (int) $message->timeStamp);
     $item['dateLabel'] = UTIL_DateTime::formatDate((int) $message->timeStamp, true);
     $item['timeStamp'] = (int) $message->timeStamp;
     $militaryTime = (bool) OW::getConfig()->getValue('base', 'military_time');
     $item['timeLabel'] = $militaryTime ? strftime("%H:%M", (int) $message->timeStamp) : strftime("%I:%M%p", (int) $message->timeStamp);
     $item['recipientId'] = (int) $message->recipientId;
     $item['senderId'] = (int) $message->senderId;
     $profileDisplayname = BOL_UserService::getInstance()->getDisplayName((int) $message->senderId);
     $profileDisplayname = empty($profileDisplayname) ? BOL_UserService::getInstance()->getUserName((int) $message->senderId) : $profileDisplayname;
     $item['displayName'] = $profileDisplayname;
     $avatarUrl = BOL_AvatarService::getInstance()->getAvatarUrl((int) $message->senderId);
     $profileAvatarUrl = empty($avatarUrl) ? $defaultAvatarUrl : $avatarUrl;
     $item['senderAvatarUrl'] = $profileAvatarUrl;
     $avatarUrl = BOL_AvatarService::getInstance()->getAvatarUrl((int) $message->recipientId);
     $profileAvatarUrl = empty($avatarUrl) ? $defaultAvatarUrl : $avatarUrl;
     $item['recipientAvatarUrl'] = $profileAvatarUrl;
     $item['isAuthor'] = (bool) ((int) $message->senderId == OW::getUser()->getId());
     $item['recipientRead'] = (int) $message->recipientRead;
     $item['isSystem'] = (int) $message->isSystem;
     $item['attachments'] = array();
     $conversation = $this->getConversation($message->conversationId);
     if ((int) $conversation->initiatorId == OW::getUser()->getId()) {
         $item['conversationViewed'] = (bool) ((int) $conversation->viewed & MAILBOX_BOL_ConversationDao::VIEW_INITIATOR);
     }
     if ((int) $conversation->interlocutorId == OW::getUser()->getId()) {
         $item['conversationViewed'] = (bool) ((int) $conversation->viewed & MAILBOX_BOL_ConversationDao::VIEW_INTERLOCUTOR);
     }
     if ($item['mode'] == 'mail') {
         $actionName = 'read_message';
     }
     if ($item['mode'] == 'chat') {
         $actionName = 'read_chat_message';
     }
     $status = BOL_AuthorizationService::getInstance()->getActionStatus('mailbox', $actionName);
     $readMessageAuthorized = true;
     if ((int) $message->senderId != OW::getUser()->getId() && !$message->wasAuthorized) {
         if ($status['status'] == BOL_AuthorizationService::STATUS_AVAILABLE) {
             if ($status['authorizedBy'] == 'usercredits') {
                 $action = USERCREDITS_BOL_CreditsService::getInstance()->findAction('mailbox', $actionName);
                 $actionPrice = USERCREDITS_BOL_CreditsService::getInstance()->findActionPriceForUser($action->id, OW::getUser()->getId());
                 if ($actionPrice->amount == 0 || $actionPrice->disabled) {
                     $readMessageAuthorized = true;
                     $this->markMessageAuthorizedToRead($message->id);
                 } else {
                     $readMessageAuthorized = false;
                     $item['isSystem'] = 1;
                     $text = array('text' => OW::getLanguage()->text('mailbox', 'api_read_the_message'), 'eventName' => 'authorizationPromoted', 'status' => 'available');
                 }
             } else {
                 $readMessageAuthorized = true;
                 $this->markMessageAuthorizedToRead($message->id);
             }
         } else {
             if ($status['status'] == BOL_AuthorizationService::STATUS_PROMOTED) {
                 $readMessageAuthorized = false;
                 $item['isSystem'] = 1;
                 $text = array('text' => strip_tags($status['msg']), 'eventName' => 'authorizationPromoted', 'status' => 'promoted');
             } else {
                 $readMessageAuthorized = false;
                 $text = OW::getLanguage()->text('mailbox', $actionName . '_permission_denied');
             }
         }
     }
     $item['readMessageAuthorized'] = $readMessageAuthorized;
     if ($readMessageAuthorized) {
         if ($message->isSystem) {
             $eventParams = json_decode($message->text, true);
             $eventParams['params']['messageId'] = (int) $message->id;
             $event = new OW_Event($eventParams['entityType'] . '.' . $eventParams['eventName'], $eventParams['params']);
             OW::getEventManager()->trigger($event);
             $data = $event->getData();
             if (!empty($data)) {
                 $text = $data;
             } else {
                 $text = array('eventName' => $eventParams['eventName'], 'text' => OW::getLanguage()->text('mailbox', 'can_not_display_entitytype_message', array('entityType' => $eventParams['entityType'])));
             }
         } else {
             $text = $this->splitLongMessages($message->text);
         }
         $attachments = $this->attachmentDao->findAttachmentsByMessageId($message->id);
         if (!empty($attachments)) {
             foreach ($attachments as $attachment) {
                 $ext = UTIL_File::getExtension($attachment->fileName);
                 $attachmentPath = $this->getAttachmentFilePath($attachment->id, $attachment->hash, $ext, $attachment->fileName);
                 $attItem = array();
                 $attItem['id'] = $attachment->id;
                 $attItem['messageId'] = $attachment->messageId;
                 $attItem['downloadUrl'] = OW::getStorage()->getFileUrl($attachmentPath);
                 $attItem['fileName'] = $attachment->fileName;
                 $attItem['fileSize'] = $attachment->fileSize;
                 $attItem['type'] = $this->getAttachmentType($attachment);
                 $item['attachments'][] = $attItem;
             }
         }
     }
     $item['text'] = $text;
     return $item;
 }
Beispiel #27
0
 public function send(array $params = null)
 {
     if (!OW::getUser()->isAuthenticated()) {
         throw new AuthenticateException();
     }
     $receiveUser = $params['id'];
     if (!OW::getUser()->isAuthorized('credits', 'send') || !OW::getAuthorization()->isUserAuthorized($receiveUser, 'credits', 'receive') || !isset($params['id'])) {
         $this->setTemplate(OW::getPluginManager()->getPlugin('base')->getCtrlViewDir() . 'authorization_failed.html');
         return;
     }
     $language = OW::getLanguage();
     $config = OW::getConfig();
     $userId = OW::getUser()->getId();
     $userCredits = USERCREDITS_BOL_CreditsService::getInstance()->getCreditsBalance($userId);
     $this->assign('userCredits', $userCredits);
     $this->assign('receiveUserName', BOL_UserService::getInstance()->getDisplayName($receiveUser));
     $form = new Form('creditForm');
     $element = new TextField('creditPoint');
     $element->setRequired(true);
     $element->setLabel($language->text('credits', 'credits_to_send'));
     $element->addAttribute("style", "width: 100px;");
     $validator = new IntValidator(1, $userCredits);
     $validator->setErrorMessage($language->text('credits', 'credit_value_error'));
     $element->addValidator($validator);
     $form->addElement($element);
     $element = new Submit('sendCredit');
     $element->setValue($language->text('credits', 'send_credits'));
     $form->addElement($element);
     if (OW::getRequest()->isPost()) {
         if ($form->isValid($_POST)) {
             $values = $form->getValues();
             $creditValue = (int) $values['creditPoint'];
             if (CREDITS_BOL_Service::getInstance()->transferCredits($userId, $receiveUser, $creditValue)) {
                 OW::getFeedback()->info($language->text('credits', 'credit_transfer_ok'));
                 $this->redirect(OW::getRouter()->urlForRoute('credits_transfer'));
             } else {
                 OW::getFeedback()->error($language->text('credits', 'credit_transfer_fail'));
             }
         }
     }
     $this->addForm($form);
     $this->setPageHeading($language->text('credits', 'transfer_credits_label'));
     $this->setPageTitle($language->text('credits', 'transfer_credits_label'));
     $this->setPageHeadingIconClass('ow_ic_gear_wheel');
 }
Beispiel #28
0
 public function onAuthLayerCheckTrackAction(BASE_CLASS_EventCollector $event)
 {
     $params = $event->getParams();
     $actionEvent = new OW_Event('usercredits.get_action_key', $params);
     OW::getEventManager()->trigger($actionEvent);
     $data = $actionEvent->getData();
     $actionName = $params['actionName'];
     $groupName = $params['groupName'];
     $actionKey = !empty($data) ? $data : $actionName;
     $userId = !empty($params['userId']) ? (int) $params['userId'] : OW::getUser()->getId();
     $extra = null;
     $checkInterval = true;
     if (isset($params['extra'])) {
         $extra = $params['extra'];
         $checkInterval = isset($params['extra']['checkInterval']) ? (bool) $params['extra']['checkInterval'] : true;
     }
     $service = USERCREDITS_BOL_CreditsService::getInstance();
     $tracked = $service->trackAction($groupName, $actionKey, $userId, $checkInterval, $extra);
     if ($tracked['status']) {
         $key = $tracked['amount'] < 0 ? 'user_spent_credits' : 'user_received_credits';
         $data = array('pluginKey' => 'usercredits', 'msg' => OW::getLanguage()->text('usercredits', $key, array('amount' => abs($tracked['amount']))), 'priority' => 2);
         $event->add($data);
     }
 }
Beispiel #29
0
 public function packs()
 {
     $menu = $this->getMenu('packs');
     $this->addComponent('menu', $menu);
     $creditService = USERCREDITS_BOL_CreditsService::getInstance();
     $lang = OW::getLanguage();
     if (!empty($_GET['delPack'])) {
         if ($creditService->deletePackById((int) $_GET['delPack'])) {
             OW::getFeedback()->info($lang->text('usercredits', 'pack_deleted'));
         }
         $this->redirectToAction('packs');
     }
     $form = new AddPackForm();
     $this->addForm($form);
     if (OW::getRequest()->isPost()) {
         if ($_POST['form_name'] == 'add-pack-form' && $form->isValid($_POST)) {
             $values = $form->getValues();
             $pack = new USERCREDITS_BOL_Pack();
             $pack->credits = (int) $values['credits'];
             $pack->accountTypeId = !empty($values['accType']) ? $values['accType'] : null;
             $pack->price = floatval($values['price']);
             if ($creditService->addPack($pack)) {
                 OW::getFeedback()->info($lang->text('usercredits', 'pack_added'));
             }
             $this->redirect();
         } else {
             if ($_POST['form_name'] == 'update-packs-form') {
                 if (!empty($_POST['credits']) && !empty($_POST['price'])) {
                     foreach ($_POST['credits'] as $packId => $credits) {
                         if (!($pack = $creditService->findPackById($packId))) {
                             continue;
                         }
                         $pack->credits = (int) $credits;
                         $pack->price = floatval($_POST['price'][$packId]);
                         $creditService->addPack($pack);
                     }
                     OW::getFeedback()->info($lang->text('usercredits', 'packs_updated'));
                 }
                 $this->redirect();
             }
         }
     }
     $accTypes = $creditService->findAccountTypes();
     if (count($accTypes) > 1) {
         $this->assign('route', OW::getRouter()->urlForRoute('usercredits.admin_packs'));
     }
     $this->assign('types', $accTypes);
     $accType = !empty($_GET['type']) ? $_GET['type'] : null;
     $this->assign('accType', $accType);
     $form->getElement('accType')->setValue($accType);
     $this->setPageHeading(OW::getLanguage()->text('usercredits', 'admin_config'));
     $this->setPageHeadingIconClass('ow_ic_gear_wheel');
     $packs = $creditService->getPackList($accType);
     $this->assign('packs', $packs);
     $this->assign('currency', BOL_BillingService::getInstance()->getActiveCurrency());
 }
Beispiel #30
0
 public function deleteTransferRecord($id, $amount)
 {
     $sentLogTable = OW_DB_PREFIX . "credits_sent_log";
     $query = "SELECT receiver,sender FROM " . $sentLogTable . " WHERE id = :id";
     $actions = OW::getDbo()->queryForList($query, array('id' => $id));
     $receiveUser = $actions[0]['receiver'];
     $sentUser = $actions[0]['sender'];
     USERCREDITS_BOL_CreditsService::getInstance()->increaseBalance($sentUser, $amount);
     USERCREDITS_BOL_CreditsService::getInstance()->decreaseBalance($receiveUser, $amount);
     $sql = "DELETE FROM `" . $sentLogTable . "` WHERE `id` = :id";
     OW::getDbo()->query($sql, array('id' => $id));
 }