/** * Fills object with all standard items of a Notification record * * @param cbpaidPayHandler $payHandler * @param int $test_ipn * @param string $log_type * @param string $paymentStatus * @param string $paymentType * @param string $reasonCode * @param int $paymentTime * @param string $charset */ public function initNotification($payHandler, $test_ipn, $log_type, $paymentStatus, $paymentType, $reasonCode, $paymentTime, $charset = 'utf-8') { $this->payment_method = $payHandler->getPayName(); $this->gateway_account = $payHandler->getAccountParam('id'); $this->log_type = $log_type; $this->time_received = Application::Database()->getUtcDateTime(); $this->ip_addresses = cbpaidRequest::getIPlist(); $this->geo_ip_country_code = cbpaidRequest::getGeoIpCountryCode(); $this->notify_version = '2.1'; $this->user_id = (int) cbGetParam($_GET, 'user', 0); $this->charset = $charset; $this->test_ipn = $test_ipn; $this->payer_status = 'unverified'; $this->payment_status = $paymentStatus; if (in_array($paymentStatus, array('Completed', 'Pending', 'Processed', 'Failed', 'Reversed', 'Refunded', 'Partially-Refunded', 'Canceled_Reversal'))) { if (in_array($paymentStatus, array('Completed', 'Reversed', 'Refunded', 'Partially-Refunded', 'Canceled_Reversal'))) { $this->payment_date = gmdate('H:i:s M d, Y T', $paymentTime); // paypal-style } $this->payment_type = $paymentType; } if ($reasonCode) { $this->reason_code = $reasonCode; } }
/** * @param bool $updateNulls * @return bool */ public function store( $updateNulls = false ) { global $_PLUGINS; $new = ( $this->get( 'id' ) ? false : true ); $old = new self(); $this->set( 'date', $this->get( 'date', Application::Database()->getUtcDateTime() ) ); if ( ! $new ) { $old->load( (int) $this->get( 'id' ) ); $_PLUGINS->trigger( 'gj_onBeforeUpdateAttendance', array( &$this, $old ) ); } else { $_PLUGINS->trigger( 'gj_onBeforeCreateAttendance', array( &$this ) ); } if ( ! parent::store( $updateNulls ) ) { return false; } if ( ! $new ) { $_PLUGINS->trigger( 'gj_onAfterUpdateAttendance', array( $this, $old ) ); } else { $_PLUGINS->trigger( 'gj_onAfterCreateAttendance', array( $this ) ); } return true; }
/** * Constructor * * @param DatabaseDriverInterface $db Database driver interface * @param boolean $silentTestLogs TRUE: Silent on successful tests */ public function __construct(DatabaseDriverInterface $db = null, $silentTestLogs = true) { if ($db === null) { $db = Application::Database(); } $this->_db = $db; $this->_silentTestLogs = $silentTestLogs; }
/** * Constructor * * @param DatabaseDriverInterface $db Database driver */ public function __construct(DatabaseDriverInterface $db = null) { if ($db === null) { $db = Application::Database(); } $this->_db = $db; $this->_silentWhenOK = false; }
/** * Constructor (allows to set non-standard table and key field) * Can be overloaded/supplemented by the child class * * @param DatabaseDriverInterface $db [optional] CB Database object * @param string $table [optional] Name of the table in the db schema relating to child class * @param string|array $key [optional] Name of the primary key field in the table */ public function __construct(DatabaseDriverInterface $db = null, $table = null, $key = null) { if ($db) { $this->_db = $db; } else { $this->_db = Application::Database(); } if ($table) { $this->_tbl = $table; } if ($key) { $this->_tbl_key = $key; } }
/** * prepare frontend events render * * @param string $return * @param GroupTable $group * @param string $users * @param string $invites * @param array $counters * @param array $buttons * @param array $menu * @param cbTabs $tabs * @param UserTable $user * @return array|null */ public function showEvents( &$return, &$group, &$users, &$invites, &$counters, &$buttons, &$menu, &$tabs, $user ) { global $_CB_framework, $_CB_database; CBGroupJive::getTemplate( 'events', true, true, $this->element ); $canModerate = ( CBGroupJive::isModerator( $user->get( 'id' ) ) || ( CBGroupJive::getGroupStatus( $user, $group ) >= 2 ) ); $limit = (int) $this->params->get( 'groups_events_limit', 15 ); $limitstart = $_CB_framework->getUserStateFromRequest( 'gj_group_events_limitstart{com_comprofiler}', 'gj_group_events_limitstart' ); $search = $_CB_framework->getUserStateFromRequest( 'gj_group_events_search{com_comprofiler}', 'gj_group_events_search' ); $where = null; if ( $search && $this->params->get( 'groups_events_search', 1 ) ) { $where .= "\n AND ( e." . $_CB_database->NameQuote( 'title' ) . " LIKE " . $_CB_database->Quote( '%' . $_CB_database->getEscaped( $search, true ) . '%', false ) . " OR e." . $_CB_database->NameQuote( 'event' ) . " LIKE " . $_CB_database->Quote( '%' . $_CB_database->getEscaped( $search, true ) . '%', false ) . " OR e." . $_CB_database->NameQuote( 'address' ) . " LIKE " . $_CB_database->Quote( '%' . $_CB_database->getEscaped( $search, true ) . '%', false ) . " OR e." . $_CB_database->NameQuote( 'location' ) . " LIKE " . $_CB_database->Quote( '%' . $_CB_database->getEscaped( $search, true ) . '%', false ) . " )"; } $searching = ( $where ? true : false ); $query = 'SELECT COUNT(*)' . "\n FROM " . $_CB_database->NameQuote( '#__groupjive_plugin_events' ) . " AS e" . "\n LEFT JOIN " . $_CB_database->NameQuote( '#__comprofiler' ) . " AS cb" . ' ON cb.' . $_CB_database->NameQuote( 'id' ) . ' = e.' . $_CB_database->NameQuote( 'user_id' ) . "\n LEFT JOIN " . $_CB_database->NameQuote( '#__users' ) . " AS j" . ' ON j.' . $_CB_database->NameQuote( 'id' ) . ' = cb.' . $_CB_database->NameQuote( 'id' ) . "\n WHERE e." . $_CB_database->NameQuote( 'group' ) . " = " . (int) $group->get( 'id' ) . "\n AND cb." . $_CB_database->NameQuote( 'approved' ) . " = 1" . "\n AND cb." . $_CB_database->NameQuote( 'confirmed' ) . " = 1" . "\n AND j." . $_CB_database->NameQuote( 'block' ) . " = 0"; if ( ! $canModerate ) { $query .= "\n AND ( e." . $_CB_database->NameQuote( 'user_id' ) . " = " . (int) $user->get( 'id' ) . ' OR e.' . $_CB_database->NameQuote( 'published' ) . ' = 1 )'; } $query .= $where; $_CB_database->setQuery( $query ); $total = (int) $_CB_database->loadResult(); if ( ( ! $total ) && ( ! $searching ) && ( ! CBGroupJive::canCreateGroupContent( $user, $group, 'events' ) ) ) { return null; } $pageNav = new cbPageNav( $total, $limitstart, $limit ); $pageNav->setInputNamePrefix( 'gj_group_events_' ); $guests = 'SELECT COUNT(*)' . "\n FROM " . $_CB_database->NameQuote( '#__groupjive_plugin_events_attendance' ) . " AS ea" . "\n LEFT JOIN " . $_CB_database->NameQuote( '#__comprofiler' ) . " AS eacb" . ' ON eacb.' . $_CB_database->NameQuote( 'id' ) . ' = ea.' . $_CB_database->NameQuote( 'user_id' ) . "\n LEFT JOIN " . $_CB_database->NameQuote( '#__users' ) . " AS eaj" . ' ON eaj.' . $_CB_database->NameQuote( 'id' ) . ' = eacb.' . $_CB_database->NameQuote( 'id' ) . "\n WHERE ea." . $_CB_database->NameQuote( 'event' ) . " = e." . $_CB_database->NameQuote( 'id' ) . "\n AND eacb." . $_CB_database->NameQuote( 'approved' ) . " = 1" . "\n AND eacb." . $_CB_database->NameQuote( 'confirmed' ) . " = 1" . "\n AND eaj." . $_CB_database->NameQuote( 'block' ) . " = 0"; $now = Application::Database()->getUtcDateTime(); $query = 'SELECT e.*' . ', TIMESTAMPDIFF( SECOND, ' . $_CB_database->Quote( $now ) . ',e.' . $_CB_database->NameQuote( 'start' ) . ' ) AS _start_ordering' . ', TIMESTAMPDIFF( SECOND, ' . $_CB_database->Quote( $now ) . ', e.' . $_CB_database->NameQuote( 'end' ) . ' ) AS _end_ordering' . ', a.' . $_CB_database->NameQuote( 'id' ) . ' AS _attending' . ', ( ' . $guests . ' ) AS _guests' . "\n FROM " . $_CB_database->NameQuote( '#__groupjive_plugin_events' ) . " AS e" . "\n LEFT JOIN " . $_CB_database->NameQuote( '#__comprofiler' ) . " AS cb" . ' ON cb.' . $_CB_database->NameQuote( 'id' ) . ' = e.' . $_CB_database->NameQuote( 'user_id' ) . "\n LEFT JOIN " . $_CB_database->NameQuote( '#__users' ) . " AS j" . ' ON j.' . $_CB_database->NameQuote( 'id' ) . ' = cb.' . $_CB_database->NameQuote( 'id' ) . "\n LEFT JOIN " . $_CB_database->NameQuote( '#__groupjive_plugin_events_attendance' ) . " AS a" . ' ON a.' . $_CB_database->NameQuote( 'user_id' ) . ' = ' . (int) $user->get( 'id' ) . ' AND a.' . $_CB_database->NameQuote( 'event' ) . ' = e.' . $_CB_database->NameQuote( 'id' ) . "\n WHERE e." . $_CB_database->NameQuote( 'group' ) . " = " . (int) $group->get( 'id' ) . "\n AND cb." . $_CB_database->NameQuote( 'approved' ) . " = 1" . "\n AND cb." . $_CB_database->NameQuote( 'confirmed' ) . " = 1" . "\n AND j." . $_CB_database->NameQuote( 'block' ) . " = 0"; if ( ! $canModerate ) { $query .= "\n AND ( e." . $_CB_database->NameQuote( 'user_id' ) . " = " . (int) $user->get( 'id' ) . ' OR e.' . $_CB_database->NameQuote( 'published' ) . ' = 1 )'; } $query .= $where . "\n ORDER BY IF( _start_ordering < 0 AND _end_ordering > 0, 1, IF( _start_ordering > 0, 2, 3 ) ), ABS( _start_ordering )"; if ( $this->params->get( 'groups_events_paging', 1 ) ) { $_CB_database->setQuery( $query, $pageNav->limitstart, $pageNav->limit ); } else { $_CB_database->setQuery( $query ); } $rows = $_CB_database->loadObjectList( null, '\CB\Plugin\GroupJiveEvents\Table\EventTable', array( $_CB_database ) ); $input = array(); $input['search'] = '<input type="text" name="gj_group_events_search" value="' . htmlspecialchars( $search ) . '" onchange="document.gjGroupEventsForm.submit();" placeholder="' . htmlspecialchars( CBTxt::T( 'Search Events...' ) ) . '" class="form-control" />'; CBGroupJiveEvents::getEvent( $rows ); CBGroupJive::preFetchUsers( $rows ); $group->set( '_events', $pageNav->total ); return array( 'id' => 'events', 'title' => CBTxt::T( 'Events' ), 'content' => HTML_groupjiveEvents::showEvents( $rows, $pageNav, $searching, $input, $counters, $group, $user, $this ) ); }
/** * @param bool $updateNulls * @return bool */ public function store( $updateNulls = false ) { global $_CB_framework, $_PLUGINS; $new = ( $this->get( 'id' ) ? false : true ); $old = new self(); $this->set( 'date', $this->get( 'date', Application::Database()->getUtcDateTime() ) ); if ( isset( $_FILES['file']['tmp_name'] ) && ( ! empty( $_FILES['file']['tmp_name'] ) ) ) { $basePath = $_CB_framework->getCfg( 'absolute_path' ) . '/images/comprofiler/cbgroupjivefile'; $filePath = $basePath . '/' . (int) $this->group()->get( 'category' ) . '/' . (int) $this->group()->get( 'id' ); CBGroupJive::createDirectory( $basePath, $this->group()->get( 'category' ), $this->group()->get( 'id' ) ); $fileExtension = strtolower( preg_replace( '/[^-a-zA-Z0-9_]/', '', pathinfo( $_FILES['file']['name'], PATHINFO_EXTENSION ) ) ); $fileName = Get::clean( pathinfo( $_FILES['file']['name'], PATHINFO_FILENAME ), GetterInterface::STRING ) . '.' . $fileExtension; $fileId = uniqid(); $newFileName = $fileId . '.' . $fileExtension; if ( ! move_uploaded_file( $_FILES['file']['tmp_name'], $filePath . '/' . $newFileName ) ) { $this->setError( CBTxt::T( 'GROUP_FILE_UPLOAD_FAILED', 'The file [file] failed to upload!', array( '[file]' => $newFileName ) ) ); return false; } else { @chmod( $filePath . '/' . $newFileName, 0755 ); } if ( $this->get( 'file' ) && file_exists( $filePath . '/' . $this->get( 'file' ) ) ) { @unlink( $filePath . '/' . $this->get( 'file' ) ); } $this->set( 'file', $newFileName ); $this->set( 'filename', $fileName ); $params = $this->params(); $params->unsetEntry( 'name' ); $params->unsetEntry( 'extension' ); $params->unsetEntry( 'mimetype' ); $params->unsetEntry( 'filesize' ); $params->set( 'name', $this->name() ); $params->set( 'extension', $this->extension() ); $params->set( 'mimetype', $this->mimeType() ); $params->set( 'filesize', $this->size( true ) ); $this->set( 'params', $params->asJson() ); } elseif ( ! $this->get( 'filename' ) ) { $this->set( 'filename', $this->get( 'file' ) ); } if ( ! $new ) { $old->load( (int) $this->get( 'id' ) ); $_PLUGINS->trigger( 'gj_onBeforeUpdateFile', array( &$this, $old ) ); } else { $_PLUGINS->trigger( 'gj_onBeforeCreateFile', array( &$this ) ); } if ( ! parent::store( $updateNulls ) ) { return false; } if ( $old->get( 'id' ) && $this->get( 'file' ) && ( $old->get( 'group' ) != $this->get( 'group' ) ) ) { $basePath = $_CB_framework->getCfg( 'absolute_path' ) . '/images/comprofiler/cbgroupjivefile'; $oldPath = $basePath . '/' . (int) $old->group()->get( 'category' ) . '/' . (int) $old->group()->get( 'id' ); $newPath = $basePath . '/' . (int) $this->group()->get( 'category' ) . '/' . (int) $this->group()->get( 'id' ); if ( is_dir( $oldPath ) ) { CBGroupJive::createDirectory( $basePath, $this->group()->get( 'category' ), $this->group()->get( 'id' ) ); if ( file_exists( $oldPath . '/' . $this->get( 'file' ) ) ) { @rename( $oldPath . '/' . $this->get( 'file' ), $newPath . '/' . $this->get( 'file' ) ); } } } if ( ! $new ) { $_PLUGINS->trigger( 'gj_onAfterUpdateFile', array( $this, $old ) ); } else { $_PLUGINS->trigger( 'gj_onAfterCreateFile', array( $this ) ); } return true; }
/** * Used internally and in promotion plugin * * @return void */ public function updateBasketRecomputeTotalizers() { $this->loadPaymentItems(); $tryAutorecurring = $this->isAnyAutoRecurring(); if ($this->payment_status == 'NotInitiated') { $timeOfBasket = cbpaidTimes::getInstance()->startTime(); $this->time_initiated = Application::Database()->getUtcDateTime($timeOfBasket); } else { $timeOfBasket = cbpaidTimes::getInstance()->strToTime($this->time_initiated); } $this->deleteTotalizers(); $this->_storeBasketItemsTotalizers($tryAutorecurring, $timeOfBasket); }
/** * Updates payment status of basket and of corresponding subscriptions if there is a change in status * * @param cbpaidPaymentBasket $paymentBasket Basket * @param string $eventType type of event (paypal type): 'web_accept', 'subscr_payment', 'subscr_signup', 'subscr_modify', 'subscr_eot', 'subscr_cancel', 'subscr_failed' * @param string $paymentStatus new status (Completed, RegistrationCancelled) * @param cbpaidPaymentNotification $notification notification object of the payment * @param int $occurrences renewal occurrences * @param int $autorecurring_type 0: not auto-recurring, 1: auto-recurring without payment processor notifications, 2: auto-renewing with processor notifications updating $expiry_date * @param int $autorenew_type 0: not auto-renewing (manual renewals), 1: asked for by user, 2: mandatory by configuration * @param boolean|string $txnIdMultiplePaymentDates FALSE: unique txn_id for each payment, TRUE: same txn_id can have multiple payment dates, additionally: 'SINGLEPAYMENT' will not look at txn_id at all * @param boolean $storePaymentRecord TRUE: normal case, create payment record if needed. FALSE: offline case where pending payment should not create a payment record. * @return void */ public function updatePaymentStatus($paymentBasket, $eventType, $paymentStatus, &$notification, $occurrences, $autorecurring_type, $autorenew_type, $txnIdMultiplePaymentDates, $storePaymentRecord = true) { global $_CB_framework, $_PLUGINS; $pluginsLoaded = false; $basketUpdateNulls = false; $previousUnifiedStatus = $this->mapPaymentStatus($paymentBasket->payment_status); $unifiedStatus = $this->mapPaymentStatus($paymentStatus); // get all related subscriptions being paid by this basket: $subscriptions = $paymentBasket->getSubscriptions(); $thisIsReferencePayment = false; $user = CBuser::getUserDataInstance((int) $paymentBasket->user_id); if ($paymentBasket->payment_status != $paymentStatus || $unifiedStatus == 'Partially-Refunded' || $autorecurring_type) { if ($paymentStatus && (in_array($eventType, array('web_accept', 'subscr_payment', 'subscr_signup')) || in_array($unifiedStatus, array('Reversed', 'Refunded', 'Partially-Refunded')))) { $paymentBasket->payment_status = $paymentStatus; } if (in_array($eventType, array('subscr_payment', 'subscr_signup'))) { $paymentBasket->recurring = 1; } if ($autorecurring_type == 0 && in_array($unifiedStatus, array('Completed', 'Processed', 'FreeTrial'))) { $paymentBasket->mc_amount1 = null; $paymentBasket->mc_amount3 = null; $paymentBasket->period1 = null; $paymentBasket->period3 = null; $basketUpdateNulls = true; } // if (count($subscriptions) >= 1) { $now = $_CB_framework->now(); $completed = false; $thisIsReferencePayment = false; $reason = null; switch ($unifiedStatus) { case 'FreeTrial': case 'Completed': case 'Processed': // this includes Canceled_Reversal !!! : if ($unifiedStatus == 'FreeTrial') { $paymentBasket->payment_status = 'Completed'; } if ($unifiedStatus == 'FreeTrial' || $unifiedStatus == 'Completed') { if ($notification->payment_date) { $time_completed = cbpaidTimes::getInstance()->gmStrToTime($notification->payment_date); } else { $time_completed = $now; } $paymentBasket->time_completed = Application::Database()->getUtcDateTime($time_completed); $completed = true; } if ($paymentStatus == 'Canceled_Reversal') { $paymentBasket->payment_status = 'Completed'; } if (is_object($notification) && isset($notification->txn_id)) { // real payment with transaction id: store as reference payment if not already stored: $thisIsReferencePayment = $this->_storePaymentOnce($paymentBasket, $notification, $now, $txnIdMultiplePaymentDates, 'Updating payment record because of new status of payment basket: ' . $unifiedStatus . ($paymentStatus != $unifiedStatus ? ' (new gateway-status: ' . $paymentStatus . ')' : '') . ' because of event received: ' . $eventType . '. Previous status was: ' . $previousUnifiedStatus); } else { // Free trials don't have a notification: $thisIsReferencePayment = true; } if ($thisIsReferencePayment) { // payment not yet processed: $autorenewed = $paymentBasket->recurring == 1 && $unifiedStatus == 'Completed' && $previousUnifiedStatus == 'Completed'; for ($i = 0, $n = count($subscriptions); $i < $n; $i++) { $reason = $autorenewed ? 'R' : $subscriptions[$i]->_reason; $subscriptions[$i]->activate($user, $now, $completed, $reason, $occurrences, $autorecurring_type, $autorenew_type, $autorenewed ? 1 : 0); } } break; case 'RegistrationCancelled': case 'Reversed': case 'Refunded': case 'Unsubscribed': if ($unifiedStatus == 'RegistrationCancelled') { if (!($previousUnifiedStatus == 'NotInitiated' || $previousUnifiedStatus === 'Pending' && $paymentBasket->payment_method === 'offline')) { return; } } for ($i = 0, $n = count($subscriptions); $i < $n; $i++) { $reason = $subscriptions[$i]->_reason; if ($reason != 'R' || in_array($unifiedStatus, array('Reversed', 'Refunded'))) { // Expired and Cancelled as well as Partially-Refunded are not reverted ! //TBD: really revert on refund everything ? a plan param would be nice here if (!in_array($previousUnifiedStatus, array('Pending', 'In-Progress', 'Denied', 'Reversed', 'Refunded')) && in_array($subscriptions[$i]->status, array('A', 'R', 'I')) && !$subscriptions[$i]->hasPendingPayment($paymentBasket->id)) { // not a cancelled or denied renewal: $subscriptions[$i]->revert($user, $unifiedStatus); } } } if ($unifiedStatus == 'RegistrationCancelled') { $paymentBasket->historySetMessage('Payment basket deleted because the subscriptions and payment got cancelled'); $paymentBasket->delete(); // deletes also payment_Items } $paidUserExtension = cbpaidUserExtension::getInstance($paymentBasket->user_id); $subscriptionsAnyAtAll = $paidUserExtension->getUserSubscriptions(''); $params = cbpaidApp::settingsParams(); $createAlsoFreeSubscriptions = $params->get('createAlsoFreeSubscriptions', 0); if (count($subscriptionsAnyAtAll) == 0 && !$createAlsoFreeSubscriptions) { $user = new UserTable(); $id = (int) cbGetParam($_GET, 'user'); $user->load((int) $id); if ($user->id && $user->block == 1) { $user->delete(null); } } break; case 'Denied': case 'Pending': if ($unifiedStatus == 'Denied') { // In fact when denied, it's the case as if the user attempted payment but failed it: He should be able to re-try: So just store the payment as denied for the records. if ($eventType == 'subscr_failed' || $eventType == 'subscr_cancel' && $autorecurring_type != 2) { // special case of a failed attempt: // or this is the final failed attempt of a basket with notifications: break; } } if ($previousUnifiedStatus == 'Completed') { return; // do not change a Completed payment as it cannot become Pending again. If we get "Pending" after "Completed", it is a messages chronological order mistake. } break; case 'In-Progress': case 'Partially-Refunded': default: break; } if ($eventType == 'subscr_cancel') { if (!in_array($unifiedStatus, array('Denied', 'Reversed', 'Refunded', 'Unsubscribed'))) { for ($i = 0, $n = count($subscriptions); $i < $n; $i++) { $subscriptions[$i]->autorecurring_cancelled($user, $unifiedStatus, $eventType); } } } for ($i = 0, $n = count($subscriptions); $i < $n; $i++) { $subscriptions[$i]->notifyPaymentStatus($unifiedStatus, $previousUnifiedStatus, $paymentBasket, $notification, $now, $user, $eventType, $paymentStatus, $occurrences, $autorecurring_type, $autorenew_type); } if (in_array($unifiedStatus, array('Denied', 'Reversed', 'Refunded', 'Partially-Refunded', 'Pending', 'In-Progress'))) { $thisIsReferencePayment = $this->_storePaymentOnce($paymentBasket, $notification, $now, $txnIdMultiplePaymentDates, 'Updating payment record because of new status of payment basket: ' . $unifiedStatus . ($paymentStatus != $unifiedStatus ? ' (new gateway-status: ' . $paymentStatus . ')' : '') . ' because of event received: ' . $eventType . '. Previous status was: ' . $previousUnifiedStatus); } // } foreach ($paymentBasket->loadPaymentTotalizers() as $totalizer) { $totalizer->notifyPaymentStatus($thisIsReferencePayment, $unifiedStatus, $previousUnifiedStatus, $paymentBasket, $notification, $now, $user, $eventType, $paymentStatus, $occurrences, $autorecurring_type, $autorenew_type, $txnIdMultiplePaymentDates); } if (!in_array($unifiedStatus, array('RegistrationCancelled'))) { if ($thisIsReferencePayment && in_array($unifiedStatus, array('Completed', 'Processed'))) { $paymentBasket->setPaidInvoiceNumber($reason); } $paymentBasket->historySetMessage('Updating payment basket ' . ($paymentStatus !== null ? 'status: ' . $unifiedStatus . ($paymentStatus != $unifiedStatus ? ' (new gateway-status: ' . $paymentStatus . ')' : '') : '') . ' because of event received: ' . $eventType . ($paymentStatus !== null ? '. Previous status was: ' . $previousUnifiedStatus : '')); $paymentBasket->store($basketUpdateNulls); } else { //TDB ? : $paymentBasket->delete(); in case of RegistrationCancelled done above, but should be done in case of FreeTrial ? (could be a param in future) } if (!in_array($unifiedStatus, array('Completed', 'Processed')) || $thisIsReferencePayment) { $_PLUGINS->loadPluginGroup('user', 'cbsubs.'); $_PLUGINS->loadPluginGroup('user/plug_cbpaidsubscriptions/plugin'); $pluginsLoaded = true; $_PLUGINS->trigger('onCPayAfterPaymentStatusChange', array(&$user, &$paymentBasket, &$subscriptions, $unifiedStatus, $previousUnifiedStatus, $occurrences, $autorecurring_type, $autorenew_type)); } } if (!in_array($unifiedStatus, array('Completed', 'Processed')) || $thisIsReferencePayment) { if (!$pluginsLoaded) { $_PLUGINS->loadPluginGroup('user', 'cbsubs.'); $_PLUGINS->loadPluginGroup('user/plug_cbpaidsubscriptions/plugin'); } $_PLUGINS->trigger('onCPayAfterPaymentStatusUpdateEvent', array(&$user, &$paymentBasket, &$subscriptions, $unifiedStatus, $previousUnifiedStatus, $eventType, &$notification)); } }
function plug_cbgroupjiveevents_install() { global $_CB_database; // Grab GJ params to migrate the legacy params: $plugin = new PluginTable(); $plugin->load( array( 'element' => 'cbgroupjive' ) ); $pluginParams = new Registry( $plugin->get( 'params' ) ); if ( $pluginParams->has( 'events_event_content' ) || ( $pluginParams->get( 'events_event_content' ) != null ) ) { // Migrate events integration parameters: $events = new PluginTable(); $events->load( array( 'element' => 'cbgroupjiveevents' ) ); $eventsParams = new Registry( $events->get( 'params' ) ); if ( ! $eventsParams->get( 'migrated' ) ) { $eventsParams->set( 'groups_events_content_plugins', $pluginParams->get( 'events_event_content' ) ); $eventsParams->set( 'groups_events_address', $pluginParams->get( 'events_plotting' ) ); $eventsParams->set( 'groups_events_captcha', $pluginParams->get( 'events_captcha' ) ); $eventsParams->set( 'groups_events_paging', $pluginParams->get( 'group_tab_paging' ) ); $eventsParams->set( 'groups_events_limit', $pluginParams->get( 'group_tab_limit' ) ); $eventsParams->set( 'groups_events_search', $pluginParams->get( 'group_tab_search' ) ); $eventsParams->set( 'migrated', true ); $events->set( 'params', $eventsParams->asJson() ); $events->store(); } } $table = '#__groupjive_plugin_events'; $fields = $_CB_database->getTableFields( $table ); if ( isset( $fields[$table]['date'] ) ) { $now = Application::Database()->getUtcDateTime(); // Move attending to attendance table: $query = 'SELECT ' . $_CB_database->NameQuote( 'id' ) . ', ' . $_CB_database->NameQuote( 'attending' ) . "\n FROM " . $_CB_database->NameQuote( '#__groupjive_plugin_events' ); $_CB_database->setQuery( $query ); $rows = $_CB_database->loadAssocList( 'id', 'attending' ); $attend = array(); foreach ( $rows as $id => $attending ) { foreach ( explode( '|*|', $attending ) as $attendee ) { $attendee = explode( ':', $attendee ); $userId = ( isset( $attendee[0] ) ? (int) $attendee[0] : null ); $attendance = ( isset( $attendee[1] ) ? (int) $attendee[1] : null ); if ( $userId && ( $attendance == 1 ) ) { $attend[] = '( ' . (int) $userId . ', ' . (int) $id . ', ' . $_CB_database->Quote( $now ) . ' )'; } } } if ( $attend ) { $query = 'INSERT IGNORE INTO '. $_CB_database->NameQuote( '#__groupjive_plugin_events_attendance' ) . ' ( ' . $_CB_database->NameQuote( 'user_id' ) . ', ' . $_CB_database->NameQuote( 'event' ) . ', ' . $_CB_database->NameQuote( 'date' ) . ' ) VALUES ' . implode( ', ', $attend ); $_CB_database->setQuery( $query ); $_CB_database->query(); } // Mode date to start: $query = 'UPDATE '. $_CB_database->NameQuote( '#__groupjive_plugin_events' ) . "\n SET " . $_CB_database->NameQuote( 'start' ) . " = " . $_CB_database->NameQuote( 'date' ); $_CB_database->setQuery( $query ); $_CB_database->query(); // Remove the old columns: $_CB_database->dropColumn( $table, 'latitude' ); $_CB_database->dropColumn( $table, 'longitude' ); $_CB_database->dropColumn( $table, 'attending' ); $_CB_database->dropColumn( $table, 'date' ); } }
/** * @param bool $updateNulls * @return bool */ public function store( $updateNulls = false ) { global $_CB_framework, $_PLUGINS; $new = ( $this->get( 'id' ) ? false : true ); $old = new self(); $this->set( 'date', $this->get( 'date', Application::Database()->getUtcDateTime() ) ); if ( isset( $_FILES['image']['tmp_name'] ) && ( ! empty( $_FILES['image']['tmp_name'] ) ) ) { static $params = null; if ( ! $params ) { $plugin = $_PLUGINS->getLoadedPlugin( 'user/plug_cbgroupjive/plugins', 'cbgroupjivephoto' ); $params = $_PLUGINS->getPluginParams( $plugin ); } $basePath = $_CB_framework->getCfg( 'absolute_path' ) . '/images/comprofiler/cbgroupjivephoto'; $filePath = $basePath . '/' . (int) $this->group()->get( 'category' ) . '/' . (int) $this->group()->get( 'id' ); CBGroupJive::createDirectory( $basePath, $this->group()->get( 'category' ), $this->group()->get( 'id' ) ); $resample = $params->get( 'groups_photo_resample', 1 ); $aspectRatio = $params->get( 'groups_photo_maintain_aspect_ratio', 1 ); $imageHeight = (int) $params->get( 'groups_photo_image_height', 640 ); if ( ! $imageHeight ) { $imageHeight = 640; } $imageWidth = (int) $params->get( 'groups_photo_image_width', 1280 ); if ( ! $imageWidth ) { $imageWidth = 1280; } $thumbHeight = (int) $params->get( 'groups_photo_thumbnail_height', 320 ); if ( ! $thumbHeight ) { $thumbHeight = 320; } $thumbWidth = (int) $params->get( 'groups_photo_thumbnail_width', 640 ); if ( ! $thumbWidth ) { $thumbWidth = 640; } $conversionType = (int) Application::Config()->get( 'conversiontype', 0 ); $imageSoftware = ( $conversionType == 5 ? 'gmagick' : ( $conversionType == 1 ? 'imagick' : 'gd' ) ); $fileExtension = strtolower( preg_replace( '/[^-a-zA-Z0-9_]/', '', pathinfo( $_FILES['image']['name'], PATHINFO_EXTENSION ) ) ); $fileName = Get::clean( pathinfo( $_FILES['image']['name'], PATHINFO_FILENAME ), GetterInterface::STRING ) . '.' . $fileExtension; $fileId = uniqid(); try { $image = new Image( $imageSoftware, $resample, $aspectRatio ); $image->setName( $fileId ); $image->setSource( $_FILES['image'] ); $image->setDestination( $filePath . '/' ); $image->processImage( $imageWidth, $imageHeight ); $newFileName = $image->getCleanFilename(); $image->setName( 'tn' . $fileId ); $image->processImage( $thumbWidth, $thumbHeight ); if ( $this->get( 'image' ) ) { if ( file_exists( $filePath . '/' . $this->get( 'image' ) ) ) { @unlink( $filePath . '/' . $this->get( 'image' ) ); } if ( file_exists( $filePath . '/tn' . $this->get( 'image' ) ) ) { @unlink( $filePath . '/tn' . $this->get( 'image' ) ); } } $this->set( 'image', $newFileName ); $this->set( 'filename', $fileName ); $params = $this->params(); $params->unsetEntry( 'name' ); $params->unsetEntry( 'extension' ); $params->unsetEntry( 'mimetype' ); $params->unsetEntry( 'filesize' ); $params->unsetEntry( 'filesize_thumbnail' ); $params->unsetEntry( 'height' ); $params->unsetEntry( 'width' ); $params->unsetEntry( 'height_thumbnail' ); $params->unsetEntry( 'width_thumbnail' ); $params->set( 'name', $this->name() ); $params->set( 'extension', $this->extension() ); $params->set( 'mimetype', $this->mimeType() ); $params->set( 'filesize', $this->size( true ) ); $params->set( 'filesize_thumbnail', $this->size( true, true ) ); $params->set( 'height', $this->height() ); $params->set( 'width', $this->width() ); $params->set( 'height_thumbnail', $this->height( true ) ); $params->set( 'width_thumbnail', $this->width( true ) ); $this->set( 'params', $params->asJson() ); } catch ( Exception $e ) { $this->setError( $e->getMessage() ); return false; } } elseif ( ! $this->get( 'filename' ) ) { $this->set( 'filename', $this->get( 'image' ) ); } if ( ! $new ) { $old->load( (int) $this->get( 'id' ) ); $_PLUGINS->trigger( 'gj_onBeforeUpdatePhoto', array( &$this, $old ) ); } else { $_PLUGINS->trigger( 'gj_onBeforeCreatePhoto', array( &$this ) ); } if ( ! parent::store( $updateNulls ) ) { return false; } if ( $old->get( 'id' ) && $this->get( 'image' ) && ( $old->get( 'group' ) != $this->get( 'group' ) ) ) { $basePath = $_CB_framework->getCfg( 'absolute_path' ) . '/images/comprofiler/cbgroupjivephoto'; $oldPath = $basePath . '/' . (int) $old->group()->get( 'category' ) . '/' . (int) $old->group()->get( 'id' ); $newPath = $basePath . '/' . (int) $this->group()->get( 'category' ) . '/' . (int) $this->group()->get( 'id' ); if ( is_dir( $oldPath ) ) { CBGroupJive::createDirectory( $basePath, $this->group()->get( 'category' ), $this->group()->get( 'id' ) ); if ( file_exists( $oldPath . '/' . $this->get( 'image' ) ) ) { @rename( $oldPath . '/' . $this->get( 'image' ), $newPath . '/' . $this->get( 'image' ) ); } if ( file_exists( $oldPath . '/tn' . $this->get( 'image' ) ) ) { @rename( $oldPath . '/tn' . $this->get( 'image' ), $newPath . '/tn' . $this->get( 'image' ) ); } } } if ( ! $new ) { $_PLUGINS->trigger( 'gj_onAfterUpdatePhoto', array( $this, $old ) ); } else { $_PLUGINS->trigger( 'gj_onAfterCreatePhoto', array( $this ) ); } return true; }
/** * Replaces wildcards * into SQL's % and adds them * @param string $operator IN+OUT: Input: '=', '<>' or '!=', OUTPUT: 'LIKE' or 'NOT LIKE' * @param string $value IN+OUT: Value to search, INPUT: with *, OUTPUT: %+sql-search-escaped * @return boolean */ protected function _replaceWildCards(&$operator, &$value) { $changes = false; if (is_array($value)) { foreach (array_keys($value) as $k) { $changes = $this->_replaceWildCards($operator, $value[$k]) || $changes; } } else { $escSearch = str_replace('|*|', '|`|', $value); if (strpos($escSearch, '*') !== false) { $escSearch = Application::Database()->getEscaped($escSearch, true); $escSearch = str_replace('*', '%', $escSearch); $value = str_replace('|`|', '|*|', $escSearch); $operator = $this->_operatorToLike($operator); $changes = true; } } return $changes; }
/** * @param bool $updateNulls * @return bool */ public function store( $updateNulls = false ) { global $_PLUGINS; $new = ( $this->get( 'id' ) ? false : true ); $old = new self(); $this->set( 'date', $this->get( 'date', Application::Database()->getUtcDateTime() ) ); if ( ! $new ) { $old->load( (int) $this->get( 'id' ) ); $_PLUGINS->trigger( 'gj_onBeforeUpdateUser', array( &$this, $old ) ); } else { $_PLUGINS->trigger( 'gj_onBeforeCreateUser', array( &$this ) ); } if ( ! parent::store( $updateNulls ) ) { return false; } // Promote to group owner if status is changed to owner: if ( $this->get( 'status' ) == 4 ) { $group = CBGroupJive::getGroup( $this->get( 'group' ) ); if ( $group->get( 'id' ) && ( $group->get( 'user_id' ) != $this->get( 'user_id' ) ) ) { $group->set( 'user_id', (int) $this->get( 'user_id' ) ); $group->store(); } } if ( ! $new ) { $_PLUGINS->trigger( 'gj_onAfterUpdateUser', array( $this, $old ) ); } else { static $params = null; if ( ! $params ) { $plugin = $_PLUGINS->getLoadedPlugin( 'user', 'cbgroupjive' ); $params = $_PLUGINS->getPluginParams( $plugin ); } // Set the default notifications: $notification = new NotificationTable(); $notification->load( array( 'user_id' => (int) $this->get( 'user_id' ), 'group' => (int) $this->get( 'group' ) ) ); $notification->set( 'user_id', (int) $this->get( 'user_id' ) ); $notification->set( 'group', (int) $this->get( 'group' ) ); $notifications = $notification->params(); $notifications->set( 'user_join', $params->get( 'notifications_default_user_join', 0 ) ); $notifications->set( 'user_leave', $params->get( 'notifications_default_user_leave', 0 ) ); $notifications->set( 'user_approve', $params->get( 'notifications_default_user_approve', 0 ) ); $notifications->set( 'user_cancel', $params->get( 'notifications_default_user_cancel', 0 ) ); $notifications->set( 'invite_accept', $params->get( 'notifications_default_invite_accept', 0 ) ); $notifications->set( 'invite_reject', $params->get( 'notifications_default_invite_reject', 0 ) ); $_PLUGINS->trigger( 'gj_onAfterCreateUser', array( $this, &$notifications ) ); $notification->set( 'params', $notifications->asJson() ); $notification->store(); } return true; }
/** * Returns date( 'Y-m-d H:i:s' or 'Y-m-d' ) but in UTC or if database time is not UTC in the CMS, taking in account system offset for database's NOW() * * @param boolean $time TRUE if time should be output too ('Y-m-d H:i:s'), FALSE if not ('Y-m-d') * @return string 'YYYY-MM-DD HH:mm:ss' if $time = TRUE, 'YYYY-MM-DD' if $time = FALSE * @deprecated 2.0 use Application::Database()->getUtcDateTime() */ function dateDbOfNow($time = true) { static $cache = array(); if (!isset($cache[$time])) { $cache[$time] = Application::Database()->getUtcDateTime(null, $time ? 'datetime' : 'date'); } return $cache[$time]; }
<?php /** * Community Builder (TM) * @version $Id: $ * @package CommunityBuilder * @copyright (C) 2004-2016 www.joomlapolis.com / Lightning MultiCom SA - and its licensors, all rights reserved * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU/GPL version 2 */ use CBLib\Application\Application; use CBLib\Database\DatabaseDriverInterface; // no direct access if (!(defined('_VALID_CB') || defined('_JEXEC') || defined('_VALID_MOS'))) { die('Direct Access to this location is not allowed.'); } /** * The classes comprofilerDBTable and CBdatabase that were in here have moved to libraries/CBLib/CB/Legacy folder. */ /** * Here for immense backwards compatibility only * * @global DatabaseDriverInterface $_CB_Database * @deprecated 2.0: Use Application::Database() instead */ global $_CB_database; $_CB_database = Application::Database();
public function postflight($type, $parent) { if (in_array($type, array('update', 'install', 'discover_install'))) { $cbDatabase = \CBLib\Application\Application::Database(); $query = 'SELECT ' . $cbDatabase->NameQuote('extension_id') . "\n FROM " . $cbDatabase->NameQuote('#__extensions') . "\n WHERE " . $cbDatabase->NameQuote('type') . " = " . $cbDatabase->Quote('component') . "\n AND " . $cbDatabase->NameQuote('element') . " = " . $cbDatabase->Quote('com_comprofiler') . "\n ORDER BY " . $cbDatabase->NameQuote('extension_id') . " DESC"; $cbDatabase->setQuery($query, 0, 1); $componentId = $cbDatabase->loadResult(); if ($componentId) { $query = 'UPDATE ' . $cbDatabase->NameQuote('#__menu') . "\n SET " . $cbDatabase->NameQuote('component_id') . " = " . (int) $componentId . "\n WHERE " . $cbDatabase->NameQuote('type') . " = " . $cbDatabase->Quote('component') . "\n AND " . $cbDatabase->NameQuote('link') . " LIKE " . $cbDatabase->Quote('%option=com_comprofiler%'); $cbDatabase->setQuery($query); $cbDatabase->query(); if (cbInstaller_create_menutype('communitybuilder', CBTxt::T('Community Builder')) === true) { cbInstaller_create_menuitem('communitybuilder', CBTxt::T('CB_PROFILE', 'CB Profile'), 'index.php?option=com_comprofiler&view=userprofile', array('component_id' => (int) $componentId)); cbInstaller_create_menuitem('communitybuilder', CBTxt::T('CB_PROFILE_EDIT', 'CB Profile Edit'), 'index.php?option=com_comprofiler&view=userdetails', array('component_id' => (int) $componentId)); cbInstaller_create_menuitem('communitybuilder', CBTxt::T('CB_REGISTRATION', 'CB Registration'), 'index.php?option=com_comprofiler&view=registers', array('component_id' => (int) $componentId)); cbInstaller_create_menuitem('communitybuilder', CBTxt::T('CB_LOGIN', 'CB Login'), 'index.php?option=com_comprofiler&view=login', array('component_id' => (int) $componentId)); cbInstaller_create_menuitem('communitybuilder', CBTxt::T('CB_LOGOUT', 'CB Logout'), 'index.php?option=com_comprofiler&view=logout', array('component_id' => (int) $componentId)); cbInstaller_create_menuitem('communitybuilder', CBTxt::T('CB_FORGOT_LOGIN', 'CB Forgot Login'), 'index.php?option=com_comprofiler&view=lostpassword', array('component_id' => (int) $componentId)); cbInstaller_create_menuitem('communitybuilder', CBTxt::T('CB_USERLIST', 'CB Userlist'), 'index.php?option=com_comprofiler&view=userslist', array('component_id' => (int) $componentId)); cbInstaller_create_menuitem('communitybuilder', CBTxt::T('CB_MANAGE_CONNECTIONS', 'CB Manage Connections'), 'index.php?option=com_comprofiler&view=manageconnections', array('component_id' => (int) $componentId)); cbInstaller_create_menuitem('communitybuilder', CBTxt::T('CB_MODERATE_BANS', 'CB Moderate Bans'), 'index.php?option=com_comprofiler&view=moderatebans', array('component_id' => (int) $componentId)); cbInstaller_create_menuitem('communitybuilder', CBTxt::T('CB_MODERATE_IMAGES', 'CB Moderate Images'), 'index.php?option=com_comprofiler&view=moderateimages', array('component_id' => (int) $componentId)); cbInstaller_create_menuitem('communitybuilder', CBTxt::T('CB_MODERATE_REPORTS', 'CB Moderate Reports'), 'index.php?option=com_comprofiler&view=moderatereports', array('component_id' => (int) $componentId)); cbInstaller_create_menuitem('communitybuilder', CBTxt::T('CB_MODERATE_USER_APPROVALS', 'CB Moderate User Approvals'), 'index.php?option=com_comprofiler&view=pendingapprovaluser', array('component_id' => (int) $componentId)); } } } }
/** * @return bool */ public function accept() { if ( $this->accepted() ) { return true; } $row = new UserTable(); $row->load( array( 'user_id' => (int) $this->get( 'user_id' ), 'group' => (int) $this->get( 'group' ) ) ); if ( ! $row->get( 'id' ) ) { $row->set( 'user_id', (int) $this->get( 'user_id' ) ); $row->set( 'group', (int) $this->get( 'group' ) ); $row->set( 'status', 1 ); if ( ! $row->store() ) { $this->setError( $row->getError() ); return false; } } $this->set( 'accepted', Application::Database()->getUtcDateTime() ); if ( ! $this->store() ) { return false; } return true; }
/** * Computes SQL DATETIME of next schedule based on $baseObject * * @param exampleScheduledClass $baseObject * @param boolean $justFailed * @return string */ public function computeMaturity($baseObject, $justFailed = false) { static $timeWords = array('S' => 'second', 'I' => 'minute', 'H' => 'hours', 'D' => 'day', 'W' => 'week', 'M' => 'month', 'Y' => 'year'); $nextMaturityTime = cbpaidTimes::getInstance()->gmStrToTime($baseObject->subscr_date); $recurrings = $baseObject->recur_times_used; // first period: if ($baseObject->period1) { $parray = explode(' ', $baseObject->period1); // e.g. '12 M' => array( '12', 'M' ) if (count($parray) == 2 && isset($timeWords[$parray[1]])) { // check format $nextMaturityTime = cbpaidTimes::getInstance()->gmStrToTime('+' . $parray[0] . ' ' . $timeWords[$parray[1]], $nextMaturityTime); // e.g. '+ 12 months' } } else { ++$recurrings; } // reoccuring period: if ($recurrings) { $parray = explode(' ', $baseObject->period3); // e.g. '12 M' => array( '12', 'M' ) if (count($parray) == 2 && isset($timeWords[$parray[1]])) { // Format is valid ? // Format is valid: $number = intval($parray[0]) * $recurrings; $nextMaturityTime = cbpaidTimes::getInstance()->gmStrToTime('+' . $number . ' ' . $timeWords[$parray[1]], $nextMaturityTime); // e.g. '+ 12 months' } } $nextMaturityTime += $baseObject->reattempts_tried * $this->retryInterval; if ($justFailed) { $tomorrow = cbpaidTimes::getInstance()->startTime() + $this->retryInterval; if ($tomorrow > $nextMaturityTime) { $nextMaturityTime = $tomorrow; } } return Application::Database()->getUtcDateTime($nextMaturityTime); }
/** * This is the frontend or backend method used directly * @see cbpaidPaymentBasket::store() * * If table key (id) is NULL : inserts a new row * otherwise updates existing row in the database table * * Can be overridden or overloaded by the child class * * @param boolean $updateNulls TRUE: null object variables are also updated, FALSE: not. * @return boolean TRUE if successful otherwise FALSE */ public function store($updateNulls = false) { global $_CB_framework, $_CB_database; // 1) check: if (!in_array($this->payment_status, array('Pending', 'Refunded', 'NotInitiated'))) { $this->setError(CBPTXT::T("This payment basket is not pending.")); return false; } if ($this->txn_id == '') { $this->txn_id = 'None'; // needed for updatePayment to generate payment record. } $paymentBasket = new cbpaidPaymentBasket($_CB_database); $paymentBasket->load($this->id); if (!$paymentBasket->gateway_account) { $this->setError(CBPTXT::T("This payment basket has no gateway associated so can not be paid manually.")); return false; } $ipn = new cbpaidPaymentNotification($_CB_database); $ipn->bindObjectToThisObject($paymentBasket, 'id'); $ipn->mc_currency = $this->mc_currency; $ipn->mc_gross = $this->mc_gross; if (!preg_match('/^[1-9][0-9]{3}-[01][0-9]-[0-3][0-9]/', $this->time_completed)) { $this->time_completed = Application::Database()->getUtcDateTime(); } $paymentBasket->time_completed = $this->time_completed; $ipn->payment_type = $this->payment_type; $paymentBasket->payment_type = $this->payment_type; $ipn->txn_id = $this->txn_id; $paymentBasket->txn_id = $this->txn_id; $ipn->payment_status = 'Completed'; $ipn->txn_type = 'web_accept'; $ipn->payment_method = $this->payment_method; $ipn->gateway_account = $this->gateway_account; $ipn->log_type = 'P'; $ipn->time_received = $_CB_database->getUtcDateTime(); $ipn->payment_date = gmdate('H:i:s M d, Y T', $this->time_completed ? cbpaidTimes::getInstance()->strToTime($this->time_completed) : cbpaidTimes::getInstance()->startTime()); // paypal-style //TBD FIXME: WE SHOULD CHANGE THIS OLD DATE STYLE ONCE WITH UTC timezone inputed $ipn->payment_basket_id = $this->id; $ipn->raw_result = 'manual'; $ipn->raw_data = ''; $ipn->ip_addresses = cbpaidRequest::getIPlist(); $ipn->user_id = Application::MyUser()->getUserId(); $ipn->txn_id = $this->txn_id; $ipn->payment_type = $this->payment_type; $ipn->charset = $_CB_framework->outputCharset(); //TBD /* $paymentBasket->first_name = $ipn->first_name = cbGetParam( $_POST, 'txtBTitle' ); $paymentBasket->first_name = $ipn->first_name = cbGetParam( $_POST, 'txtBFirstName' ); $paymentBasket->last_name = $ipn->last_name = cbGetParam( $_POST, 'txtBLastName' ); $paymentBasket->address_street = $ipn->address_street = cbGetParam( $_POST, 'txtBAddr1' ); $paymentBasket->address_zip = $ipn->address_zip = cbGetParam( $_POST, 'txtBZipCode' ); $paymentBasket->address_city = $ipn->address_city = cbGetParam( $_POST, 'txtBCity' ); $paymentBasket->address_country = $ipn->address_country = cbGetParam( $_POST, 'txtBCountry' ); //TBD? $paymentBasket->phone = $ipn->phone = cbGetParam( $_POST, 'txtBTel' ); //TBD? $paymentBasket->fax = $ipn->fax = cbGetParam( $_POST, 'txtBFax' ); $paymentBasket->payer_email = $ipn->payer_email = cbGetParam( $_POST, 'txtBEmail' ); */ if (!$_CB_database->insertObject($ipn->getTableName(), $ipn, $ipn->getKeyName())) { trigger_error('store error:' . htmlspecialchars($_CB_database->getErrorMsg()), E_USER_ERROR); //TBD also in paypal: error code 500 !!! } $payAccount = cbpaidControllerPaychoices::getInstance()->getPayAccount($paymentBasket->gateway_account); if (!$payAccount) { $this->setError(CBPTXT::T("This payment basket's associated gateway account is not active, so can not be paid manually.")); return false; } $payClass = $payAccount->getPayMean(); $payClass->updatePaymentStatus($paymentBasket, 'web_accept', 'Completed', $ipn, 1, 0, 0, 'singlepayment'); return true; }
/** * @param bool $updateNulls * @return bool */ public function store( $updateNulls = false ) { global $_CB_framework, $_PLUGINS; $new = ( $this->get( 'id' ) ? false : true ); $old = new self(); $this->set( 'date', $this->get( 'date', Application::Database()->getUtcDateTime() ) ); if ( ! $new ) { $old->load( (int) $this->get( 'id' ) ); $_PLUGINS->trigger( 'gj_onBeforeUpdateGroup', array( &$this, $old ) ); } else { $_PLUGINS->trigger( 'gj_onBeforeCreateGroup', array( &$this ) ); } if ( ! parent::store( $updateNulls ) ) { return false; } if ( ! CBGroupJive::uploadImage( 'canvas', $this ) ) { return false; } if ( ! CBGroupJive::uploadImage( 'logo', $this ) ) { return false; } if ( ! parent::store( $updateNulls ) ) { return false; } // If the new owner doesn't match the previous then demote (frontend) or delete (backend) the previous: if ( $old->get( 'id' ) ) { if ( $old->get( 'user_id' ) != $this->get( 'user_id' ) ) { $previousUser = new UserTable(); $previousUser->load( array( 'user_id' => (int) $old->get( 'user_id' ), 'group' => (int) $this->get( 'id' ) ) ); if ( $previousUser->get( 'id' ) ) { if ( Application::Cms()->getClientId() ) { if ( ! $previousUser->delete() ) { $this->setError( $previousUser->getError() ); return false; } } else { $previousUser->set( 'status', 1 ); if ( ! $previousUser->store() ) { $this->setError( $previousUser->getError() ); return false; } } } } } $user = new UserTable(); $user->load( array( 'user_id' => (int) $this->get( 'user_id' ), 'group' => (int) $this->get( 'id' ) ) ); // If the owner doesn't exist or isn't marked owner then create them or promote them to owner: if ( ( ! $user->get( 'id' ) ) || ( $user->get( 'status' ) != 4 ) ) { $user->set( 'user_id', (int) $this->get( 'user_id' ) ); $user->set( 'group', (int) $this->get( 'id' ) ); $user->set( 'status', 4 ); if ( $user->getError() || ( ! $user->store() ) ) { $this->setError( $user->getError() ); return false; } } // If the category is changed be sure to move the canvas and logo as needed: if ( $old->get( 'id' ) && ( $this->get( 'canvas' ) || $this->get( 'logo' ) ) && ( $old->get( 'category' ) != $this->get( 'category' ) ) ) { $basePath = $_CB_framework->getCfg( 'absolute_path' ) . '/images/comprofiler/plug_cbgroupjive'; $oldPath = $basePath . '/' . (int) $old->get( 'category' ) . '/' . (int) $this->get( 'id' ); $newPath = $basePath . '/' . (int) $this->get( 'category' ) . '/' . (int) $this->get( 'id' ); if ( is_dir( $oldPath ) ) { CBGroupJive::createDirectory( $basePath, $this->get( 'category' ), $this->get( 'id' ) ); CBGroupJive::copyDirectory( $oldPath, $newPath, true ); } } if ( ! $new ) { $_PLUGINS->trigger( 'gj_onAfterUpdateGroup', array( $this, $old ) ); } else { $_PLUGINS->trigger( 'gj_onAfterCreateGroup', array( $this ) ); } return true; }
/** * send group message * * @param int $id * @param UserTable $user */ private function sendMessage( $id, $user ) { global $_CB_framework, $_CB_database; $row = CBGroupJive::getGroup( $id ); $returnUrl = $_CB_framework->pluginClassUrl( $this->element, false, array( 'action' => 'groups', 'func' => 'show', 'id' => (int) $row->get( 'id' ) ) ); if ( CBGroupJive::canAccessGroup( $row, $user ) ) { if ( ! CBGroupJive::isModerator( $user->get( 'id' ) ) ) { if ( ! $this->params->get( 'groups_message', 0 ) ) { cbRedirect( $returnUrl, CBTxt::T( 'You do not have access to messaging in this group.' ), 'error' ); } elseif ( ( $row->get( 'published' ) == -1 ) || ( CBGroupJive::getGroupStatus( $user, $row ) < 3 ) ) { cbRedirect( $returnUrl, CBTxt::T( 'You do not have sufficient permissions to messaging in this group.' ), 'error' ); } elseif ( $row->params()->get( 'messaged' ) ) { $seconds = (int) $this->params->get( 'groups_message_delay', 60 ); if ( $seconds ) { $diff = Application::Date( 'now', 'UTC' )->diff( $row->get( 'messaged' ) ); if ( ( $diff === false ) || ( $diff->s < $seconds ) ) { cbRedirect( $returnUrl, CBTxt::T( 'You can not send a message to this group at this time. Please wait awhile and try again.' ), 'error' ); } } } } } else { CBGroupJive::returnRedirect( $returnUrl, CBTxt::T( 'Group does not exist.' ), 'error' ); } $message = $this->input( 'post/message', null, GetterInterface::STRING ); if ( ! $message ) { $_CB_framework->enqueueMessage( CBTxt::T( 'GROUP_MESSAGE_FAILED_TO_SEND', 'Group message failed to send! Error: [error]', array( '[error]' => CBTxt::T( 'Message not specified!' ) ) ), 'error' ); $this->showGroupMessage( $id, $user ); return; } $query = 'SELECT cb.*, j.*' . "\n FROM " . $_CB_database->NameQuote( '#__groupjive_users' ) . " AS u" . "\n LEFT JOIN " . $_CB_database->NameQuote( '#__comprofiler' ) . " AS cb" . ' ON cb.' . $_CB_database->NameQuote( 'id' ) . ' = u.' . $_CB_database->NameQuote( 'user_id' ) . "\n LEFT JOIN " . $_CB_database->NameQuote( '#__users' ) . " AS j" . ' ON j.' . $_CB_database->NameQuote( 'id' ) . ' = cb.' . $_CB_database->NameQuote( 'id' ) . "\n WHERE u." . $_CB_database->NameQuote( 'user_id' ) . " != " . (int) $user->get( 'id' ) . "\n AND u." . $_CB_database->NameQuote( 'group' ) . " = " . (int) $row->get( 'id' ) . "\n AND cb." . $_CB_database->NameQuote( 'approved' ) . " = 1" . "\n AND cb." . $_CB_database->NameQuote( 'confirmed' ) . " = 1" . "\n AND j." . $_CB_database->NameQuote( 'block' ) . " = 0" . "\n AND u." . $_CB_database->NameQuote( 'status' ) . " > 0"; $_CB_database->setQuery( $query ); $users = $_CB_database->loadObjectList( null, '\CB\Database\Table\UserTable', array( $_CB_database ) ); if ( ! $users ) { CBGroupJive::returnRedirect( $returnUrl, CBTxt::T( 'This group has no users to message.' ) ); } else { foreach ( $users as $usr ) { CBGroupJive::sendNotification( $this->params->get( 'groups_message_type', 2 ), $user, $usr, CBTxt::T( 'Group message' ), CBTxt::T( 'GROUP_MESSAGE', 'Group [group] has sent the following message.<p>[message]</p>', array( '[message]' => $message ) ), $row ); } } $row->params()->set( 'messaged', Application::Database()->getUtcDateTime() ); $row->set( 'params', $row->params()->asJson() ); if ( $row->getError() || ( ! $row->store() ) ) { $_CB_framework->enqueueMessage( CBTxt::T( 'GROUP_FAILED_TO_SAVE', 'Group failed to save! Error: [error]', array( '[error]' => $row->getError() ) ), 'error' ); $this->showGroupMessage( $id, $user ); return; } CBGroupJive::returnRedirect( $returnUrl, CBTxt::T( 'Group messaged successfully!' ) ); }
/** * binds a payment notification object for a basket to this payment. * * @param cbpaidPaymentBasket $paymentBasket * @param cbpaidPaymentNotification $notification * @param string $paymentDate in format 'Y-m-d H:i:s' * @param int $now * @return void */ public function bindPayment($paymentBasket, $notification, $paymentDate, $now) { $ignore = 'id payment_basket_id payment_method gateway_account log_id for_user_id by_user_id to_user_id ' . 'created_by_user_id modified_by_user_id time_paid time_created time_modified'; $this->bindObjectToThisObject($notification, $ignore); if (in_array($this->payment_status, array('Processed', 'Reversed', 'Refunded', 'Partially-Refunded', 'Canceled_Reversal'))) { $this->payment_status = 'Completed'; // the payment is negative, but succeeded } $this->payment_basket_id = $paymentBasket->id; $this->payment_method = $notification->payment_method; $this->gateway_account = $notification->gateway_account; $this->log_id = $notification->id; $this->for_user_id = $paymentBasket->user_id; $this->by_user_id = $paymentBasket->user_id; //TBD v2 $this->to_user_id = 0; //TBD v2 $this->created_by_user_id = 0; $this->modified_by_user_id = 0; $this->time_paid = $paymentDate; $this->time_created = Application::Database()->getUtcDateTime($now); $this->time_modified = null; }