Пример #1
0
 /**
  * Build an SQL query to load the list data.
  *
  * @return  JDatabaseQuery
  *
  * @since   1.6
  */
 protected function getListQuery()
 {
     // Create a new query object.
     $db = $this->getDbo();
     $query = $db->getQuery(true);
     // Select the required fields from the table.
     $query->select($this->getState('list.select', 'a.*'));
     $query->from($db->quoteName('#__users') . ' AS a');
     // If the model is set to check item state, add to the query.
     $state = $this->getState('filter.state');
     if (is_numeric($state)) {
         $query->where('a.block = ' . (int) $state);
     }
     // If the model is set to check the activated state, add to the query.
     $active = $this->getState('filter.active');
     if (is_numeric($active)) {
         if ($active == '0') {
             $query->where('a.activation = ' . $db->quote(''));
         } elseif ($active == '1') {
             $query->where($query->length('a.activation') . ' = 32');
         }
     }
     // Filter the items over the group id if set.
     $groupId = $this->getState('filter.group_id');
     $groups = $this->getState('filter.groups');
     if ($groupId || isset($groups)) {
         $query->join('LEFT', '#__user_usergroup_map AS map2 ON map2.user_id = a.id');
         $query->group($db->quoteName(array('a.id', 'a.name', 'a.username', 'a.password', 'a.usertype', 'a.block', 'a.sendEmail', 'a.registerDate', 'a.lastvisitDate', 'a.activation', 'a.params', 'a.email')));
         if ($groupId) {
             $query->where('map2.group_id = ' . (int) $groupId);
         }
         if (isset($groups)) {
             $query->where('map2.group_id IN (' . implode(',', $groups) . ')');
         }
     }
     // Filter the items over the search string if set.
     if ($this->getState('filter.search') !== '') {
         // Escape the search token.
         $token = $db->Quote('%' . $db->escape($this->getState('filter.search')) . '%');
         // Compile the different search clauses.
         $searches = array();
         $searches[] = 'a.name LIKE ' . $token;
         $searches[] = 'a.username LIKE ' . $token;
         $searches[] = 'a.email LIKE ' . $token;
         // Add the clauses to the query.
         $query->where('(' . implode(' OR ', $searches) . ')');
     }
     // Add filter for registration ranges select list
     $range = $this->getState('filter.range');
     // Apply the range filter.
     if ($range = $this->getState('filter.range')) {
         // Get UTC for now.
         $dNow = new JDate();
         $dStart = clone $dNow;
         switch ($range) {
             case 'past_week':
                 $dStart->modify('-7 day');
                 break;
             case 'past_1month':
                 $dStart->modify('-1 month');
                 break;
             case 'past_3month':
                 $dStart->modify('-3 month');
                 break;
             case 'past_6month':
                 $dStart->modify('-6 month');
                 break;
             case 'post_year':
             case 'past_year':
                 $dStart->modify('-1 year');
                 break;
             case 'today':
                 // Ranges that need to align with local 'days' need special treatment.
                 $app = JFactory::getApplication();
                 $offset = $app->getCfg('offset');
                 // Reset the start time to be the beginning of today, local time.
                 $dStart = new JDate('now', $offset);
                 $dStart->setTime(0, 0, 0);
                 // Now change the timezone back to UTC.
                 $tz = new DateTimeZone('GMT');
                 $dStart->setTimezone($tz);
                 break;
         }
         if ($range == 'post_year') {
             $query->where($db->quoteName('a.registerDate') . ' < ' . $db->quote($dStart->format('Y-m-d H:i:s')));
         } else {
             $query->where($db->quoteName('a.registerDate') . ' >= ' . $db->quote($dStart->format('Y-m-d H:i:s')) . ' AND ' . $db->quoteName('a.registerDate') . ' <=' . $db->quote($dNow->format('Y-m-d H:i:s')));
         }
     }
     // Filter by excluded users
     $excluded = $this->getState('filter.excluded');
     if (!empty($excluded)) {
         $query->where('id NOT IN (' . implode(',', $excluded) . ')');
     }
     // Add the list ordering clause.
     $query->order($db->escape($this->getState('list.ordering', 'a.name')) . ' ' . $db->escape($this->getState('list.direction', 'ASC')));
     return $query;
 }
Пример #2
0
 /**
  * Time creation of start and end time/date of event is flexible
  * When the end event is not specified a default action is to create a duration of DEFAULT_DURATION_OF_EVENT of event
  * @param DateTime $startDate date when the event is start
  * @param DateTime $endDate date when the event is ended
  * @return Array (mixed)
  * 			$arr['startDate'] = JDate $startDate,
  * 			$arr['endDate'] = JDate $endDate
  */
 public function determinedEventDuration($startDate, $endDate)
 {
     /**
      * Time Reasoning
      * ----------
      * Start Date and Start Time is validated with Javascript both is compulsory as the entries will be stored in actual time format
      * In this case, if the 12:00am is the intended time, the system can determined what is expected outcome of the creation
      * On the other hand, if the 12:00am is consider as default value or unset time, it's harder to guest their action
      *
      * Logic:
      * If the Start (Date && Time) is specified but End (Date && Time) is not the value of End (Date && Time) is DEFAULT_DURATION_OF_EVENT
      */
     $result['startDate'] = $result['startTime'] = NULL;
     $result['endDate'] = $result['endTime'] = NULL;
     /* if the time is a valid time simply return a JDate object */
     if (!empty($startDate) && strpos($startDate, '0000-00-00 00:00') === false) {
         $result['startDate'] = new JDate($startDate);
         $result['startTime'] = $result['startDate']->format(JText::_('JXLIB_TIME_SHORT_FORMAT'));
     }
     /* if the time is a valid time simply return a JDate object */
     if (!empty($endDate) && strpos($endDate, '0000-00-00 00:00') === false) {
         $result['endDate'] = new JDate($endDate);
         $result['endTime'] = $result['endDate']->format(JText::_('JXLIB_TIME_SHORT_FORMAT'));
     }
     /* Output is normal, return now */
     if (!in_array(NULL, $result)) {
         return $result;
     }
     if (!$startDate instanceof JDate) {
         $startDate = new JDate($startDate);
     }
     if (!$endDate instanceof JDate) {
         $endDate = new JDate($endDate);
     }
     /* sometime epoch date might exist with altered time */
     if (strpos($startDate, '0000-00-00 00:00') === true || preg_match('/-0001-11-30\\s(\\d{2}:){2}\\d{2}/', $startDate)) {
         $date = new JDate();
         /* begin the date at the start of the day */
         $date->setTime(0, 0, 0);
         $result['startDate'] = $startDate = $date;
         $result['startTime'] = $startTime = $startDate->format(JText::_('JXLIB_TIME_SHORT_FORMAT'));
     }
     /**
      * If no end of event the duration will be increased by DEFAULT_DURATION_OF_EVENT
      * JDate can reset the date to defaulted epoch time
      */
     if (strpos($endDate, '0000-00-00 00:00') == true || preg_match('/-0001-11-30\\s(\\d{2}:){2}\\d{2}/', $endDate)) {
         $result['endDate'] = $endDate = $startDate->modify(self::DEFAULT_DURATION_OF_EVENT);
         $result['endTime'] = $endTime = $endDate->format(JText::_('JXLIB_TIME_SHORT_FORMAT'));
     }
     return $result;
 }
Пример #3
0
 function quickAddRate()
 {
     AImporter::model('transport');
     $mainframe = JFactory::getApplication();
     $input = JFactory::getApplication()->input;
     $transport_id = $input->getInt('transport_id');
     $model = new BookProModelTransport();
     $transport = $model->getItem($transport_id);
     $params = $transport->rate_params;
     $weekdays = array(0, 1, 2, 3, 4, 5, 6);
     $startdate = new JDate();
     $startdate->setTime('00', '00', '00');
     $enddate = clone $startdate;
     $enddate->add(new DateInterval('P60D'));
     $frate = array('private_price' => null, 'private_state' => 0, 'share_price' => null, 'share_state' => 0);
     if (!empty($transport->private_price)) {
         $frate['private_price'] = $transport->private_price;
         $frate['private_state'] = 1;
     }
     if (!empty($transport->share_price)) {
         $frate['share_price'] = $transport->share_price;
         $frate['share_state'] = 1;
     }
     $result = $this->saveOne($weekdays, $frate, $transport_id, $startdate, $enddate, $params);
     if ($result) {
         $mainframe->enqueueMessage('Add rate from ' . JFactory::getDate()->format('Y-m-d', true) . ' to ' . $enddate->format('Y-m-d') . ' successful!');
     } else {
         $mainframe->enqueueMessage('Failed', 'error');
     }
     $this->setRedirect('index.php?option=com_bookpro&view=transports');
     return;
 }
Пример #4
0
 /**
  * User export
  *
  * @copyright
  * @author		RolandD
  * @todo
  * @see
  * @access 		public
  * @param
  * @return 		void
  * @since 		3.4
  */
 public function getStart()
 {
     // Get some basic data
     $db = JFactory::getDbo();
     $csvidb = new CsviDb();
     $jinput = JFactory::getApplication()->input;
     $csvilog = $jinput->get('csvilog', null, null);
     $template = $jinput->get('template', null, null);
     $exportclass = $jinput->get('export.class', null, null);
     $export_fields = $jinput->get('export.fields', array(), 'array');
     $sef = new CsviSef();
     // Build something fancy to only get the fieldnames the user wants
     $userfields = array();
     foreach ($export_fields as $column_id => $field) {
         switch ($field->field_name) {
             case 'fullname':
                 $userfields[] = $db->qn('u.name', 'fullname');
                 break;
             case 'usergroup_name':
                 $userfields[] = $db->qn('id');
                 break;
             case 'custom':
                 break;
             default:
                 $userfields[] = $db->qn($field->field_name);
                 break;
         }
     }
     // Build the query
     $userfields = array_unique($userfields);
     $query = $db->getQuery(true);
     $query->select(implode(",\n", $userfields));
     $query->from($db->qn("#__users", "u"));
     $selectors = array();
     // Filter by published state
     $user_state = $template->get('user_state', 'user');
     if ($user_state != '*') {
         $selectors[] = $db->qn('u.block') . ' = ' . $user_state;
     }
     // Filter by active state
     $user_active = $template->get('user_active', 'user');
     if ($user_active == '0') {
         $selectors[] = $db->qn('u.activation') . ' = ' . $db->q('');
     } elseif ($user_active == '1') {
         $selectors[] = $db->qn('u.activation') . ' = ' . $db->q('32');
     }
     // Filter by user group
     $user_groups = $template->get('user_group', 'user');
     if ($user_groups && $user_groups[0] != '*') {
         $query->join('LEFT', $db->qn('#__user_usergroup_map', 'map2') . ' ON ' . $db->qn('map2.user_id') . ' = ' . $db->qn('u.id'));
         if (isset($user_groups)) {
             $selectors[] = $db->qn('map2.group_id') . ' IN (' . implode(',', $user_groups) . ')';
         }
     }
     // Filter on range
     $user_range = $template->get('user_range', 'user');
     if ($user_range != '*') {
         jimport('joomla.utilities.date');
         // Get UTC for now.
         $dNow = new JDate();
         $dStart = clone $dNow;
         switch ($user_range) {
             case 'past_week':
                 $dStart->modify('-7 day');
                 break;
             case 'past_1month':
                 $dStart->modify('-1 month');
                 break;
             case 'past_3month':
                 $dStart->modify('-3 month');
                 break;
             case 'past_6month':
                 $dStart->modify('-6 month');
                 break;
             case 'post_year':
             case 'past_year':
                 $dStart->modify('-1 year');
                 break;
             case 'today':
                 // Ranges that need to align with local 'days' need special treatment.
                 $app = JFactory::getApplication();
                 $offset = $app->getCfg('offset');
                 // Reset the start time to be the beginning of today, local time.
                 $dStart = new JDate('now', $offset);
                 $dStart->setTime(0, 0, 0);
                 // Now change the timezone back to UTC.
                 $tz = new DateTimeZone('GMT');
                 $dStart->setTimezone($tz);
                 break;
         }
         if ($user_range == 'post_year') {
             $selectors[] = $db->qn('u.registerDate') . ' < ' . $db->q($dStart->format('Y-m-d H:i:s'));
         } else {
             $selectors[] = $db->qn('u.registerDate') . ' >= ' . $db->q($dStart->format('Y-m-d H:i:s')) . ' AND u.registerDate <=' . $db->q($dNow->format('Y-m-d H:i:s'));
         }
     }
     // Check if we need to attach any selectors to the query
     if (count($selectors) > 0) {
         $query->where(implode("\n AND ", $selectors));
     }
     // Ingore fields
     $ignore = array('custom', 'fullname', 'usergroup_name');
     // Check if we need to group the users together
     $groupby = $template->get('groupby', 'general', false, 'bool');
     if ($groupby) {
         $filter = $this->getFilterBy('groupby', $ignore);
         if (!empty($filter)) {
             $query->group($filter);
         }
     }
     // Order by set field
     $orderby = $this->getFilterBy('sort', $ignore);
     if (!empty($orderby)) {
         $query->order($orderby);
     }
     // Add a limit if user wants us to
     $limits = $this->getExportLimit();
     // Execute the query
     $csvidb->setQuery($query, $limits['offset'], $limits['limit']);
     $csvilog->addDebug(JText::_('COM_CSVI_EXPORT_QUERY'), true);
     // There are no records, write SQL query to log
     if (!is_null($csvidb->getErrorMsg())) {
         $this->addExportContent(JText::sprintf('COM_CSVI_ERROR_RETRIEVING_DATA', $csvidb->getErrorMsg()));
         $this->writeOutput();
         $csvilog->AddStats('incorrect', $csvidb->getErrorMsg());
     } else {
         $logcount = $csvidb->getNumRows();
         $jinput->set('logcount', $logcount);
         if ($logcount > 0) {
             while ($record = $csvidb->getRow()) {
                 if ($template->get('export_file', 'general') == 'xml' || $template->get('export_file', 'general') == 'html') {
                     $this->addExportContent($exportclass->NodeStart());
                 }
                 foreach ($export_fields as $column_id => $field) {
                     $fieldname = $field->field_name;
                     $fieldreplace = $field->field_name . $field->column_header;
                     // Add the replacement
                     if (isset($record->{$fieldname})) {
                         $fieldvalue = CsviHelper::replaceValue($field->replace, $record->{$fieldname});
                     } else {
                         $fieldvalue = '';
                     }
                     switch ($fieldname) {
                         case 'usergroup_name':
                             $query = $db->getQuery(true);
                             $query->select($db->qn('title'));
                             $query->from($db->qn('#__usergroups'));
                             $query->leftJoin($db->qn('#__user_usergroup_map') . ' ON ' . $db->qn('#__user_usergroup_map.group_id') . ' = ' . $db->qn('#__usergroups.id'));
                             $query->where($db->qn('user_id') . ' = ' . $record->id);
                             $db->setQuery($query);
                             $groups = $db->loadColumn();
                             if (is_array($groups)) {
                                 $fieldvalue = implode('|', $groups);
                             } else {
                                 $fieldvalue = '';
                             }
                             if (strlen(trim($fieldvalue)) == 0) {
                                 $fieldvalue = $field->default_value;
                             }
                             $record->output[$column_id] = $fieldvalue;
                             break;
                         case 'custom':
                             if (strlen(trim($fieldvalue)) == 0) {
                                 $fieldvalue = $field->default_value;
                             }
                             $fieldvalue = CsviHelper::replaceValue($field->replace, $fieldvalue);
                             $record->output[$column_id] = $fieldvalue;
                             break;
                         default:
                             // Check if we have any content otherwise use the default value
                             if (strlen(trim($fieldvalue)) == 0) {
                                 $fieldvalue = $field->default_value;
                             }
                             $record->output[$column_id] = $fieldvalue;
                             break;
                     }
                 }
                 // Output the data
                 $this->addExportFields($record);
                 if ($template->get('export_file', 'general') == 'xml' || $template->get('export_file', 'general') == 'html') {
                     $this->addExportContent($exportclass->NodeEnd());
                 }
                 // Output the contents
                 $this->writeOutput();
             }
         } else {
             $this->addExportContent(JText::_('COM_CSVI_NO_DATA_FOUND'));
             // Output the contents
             $this->writeOutput();
         }
     }
 }
Пример #5
0
 /**
  * Construct the date range to filter on.
  *
  * @param   string  $range  The textual range to construct the filter for.
  *
  * @return  string  The date range to filter on.
  *
  * @since   3.6.0
  */
 private function buildDateRange($range)
 {
     // Get UTC for now.
     $dNow = new JDate();
     $dStart = clone $dNow;
     switch ($range) {
         case 'past_week':
             $dStart->modify('-7 day');
             break;
         case 'past_1month':
             $dStart->modify('-1 month');
             break;
         case 'past_3month':
             $dStart->modify('-3 month');
             break;
         case 'past_6month':
             $dStart->modify('-6 month');
             break;
         case 'post_year':
             $dNow = false;
         case 'past_year':
             $dStart->modify('-1 year');
             break;
         case 'today':
             // Ranges that need to align with local 'days' need special treatment.
             $app = JFactory::getApplication();
             $offset = $app->get('offset');
             // Reset the start time to be the beginning of today, local time.
             $dStart = new JDate('now', $offset);
             $dStart->setTime(0, 0, 0);
             // Now change the timezone back to UTC.
             $tz = new DateTimeZone('GMT');
             $dStart->setTimezone($tz);
             break;
         case 'never':
             $dNow = false;
             $dStart = $this->_db->getNullDate();
             break;
     }
     return array('dNow' => $dNow, 'dStart' => $dStart);
 }
Пример #6
0
 /**
  * Process payment transaction.
  *
  * @param string                   $context
  * @param object                   $item
  * @param Joomla\Registry\Registry $params
  *
  * @return null|array
  */
 public function onPaymentsCheckout($context, &$item, &$params)
 {
     if (strcmp("com_crowdfunding.payments.checkout.paypal", $context) != 0) {
         return null;
     }
     if ($this->app->isAdmin()) {
         return null;
     }
     $doc = JFactory::getDocument();
     /**  @var $doc JDocumentHtml */
     // Check document type
     $docType = $doc->getType();
     if (strcmp("html", $docType) != 0) {
         return null;
     }
     $output = array();
     $notifyUrl = $this->getCallbackUrl();
     $cancelUrl = $this->getCancelUrl($item->slug, $item->catslug);
     $returnUrl = $this->getReturnUrl($item->slug, $item->catslug);
     // DEBUG DATA
     JDEBUG ? $this->log->add(JText::_($this->textPrefix . "_DEBUG_NOTIFY_URL"), $this->debugType, $notifyUrl) : null;
     JDEBUG ? $this->log->add(JText::_($this->textPrefix . "_DEBUG_RETURN_URL"), $this->debugType, $returnUrl) : null;
     JDEBUG ? $this->log->add(JText::_($this->textPrefix . "_DEBUG_CANCEL_URL"), $this->debugType, $cancelUrl) : null;
     // Get country and locale code.
     $countryId = $this->params->get("paypal_country");
     $country = new Crowdfunding\Country(JFactory::getDbo());
     $country->load($countryId);
     // Create transport object.
     $options = new Joomla\Registry\Registry();
     /** @var  $options Joomla\Registry\Registry */
     $transport = new JHttpTransportCurl($options);
     $http = new JHttp($options, $transport);
     // Create payment object.
     $options = new Joomla\Registry\Registry();
     /** @var  $options Joomla\Registry\Registry */
     $options->set("urls.cancel", $cancelUrl);
     $options->set("urls.return", $returnUrl);
     $options->set("urls.notify", $notifyUrl);
     $this->prepareCredentials($options);
     // Get server IP address.
     /*$serverIP = $this->app->input->server->get("SERVER_ADDR");
       $options->set("credentials.ip_address", $serverIP);*/
     // Prepare starting and ending date.
     if (!$this->params->get("paypal_starting_date", 0)) {
         // End date of the campaign.
         $startingDate = new JDate();
         // Today
         $startingDate->setTime(0, 0, 0);
         // At 00:00:00
     } else {
         $startingDate = new JDate($item->ending_date);
         $startingDate->modify("+1 day");
         $startingDate->setTime(0, 0, 0);
         // At 00:00:00
     }
     $endingDate = new JDate($item->ending_date);
     $endingDate->modify("+10 days");
     $options->set("payment.starting_date", $startingDate->format(DATE_ATOM));
     $options->set("payment.ending_date", $endingDate->format(DATE_ATOM));
     $options->set("payment.max_amount", $item->amount);
     $options->set("payment.max_total_amount", $item->amount);
     $options->set("payment.number_of_payments", 1);
     $options->set("payment.currency_code", $item->currencyCode);
     $options->set("payment.fees_payer", $this->params->get("paypal_fees_payer"));
     $options->set("payment.ping_type", "NOT_REQUIRED");
     $title = JText::sprintf($this->textPrefix . "_INVESTING_IN_S", htmlentities($item->title, ENT_QUOTES, "UTF-8"));
     $options->set("payment.memo", $title);
     $options->set("request.envelope", $this->envelope);
     // Get payment session.
     $paymentSessionContext = Crowdfunding\Constants::PAYMENT_SESSION_CONTEXT . $item->id;
     $paymentSessionLocal = $this->app->getUserState($paymentSessionContext);
     $paymentSession = $this->getPaymentSession(array("session_id" => $paymentSessionLocal->session_id));
     // Get API url.
     $apiUrl = $this->getApiUrl();
     // DEBUG DATA
     JDEBUG ? $this->log->add(JText::_($this->textPrefix . "_DEBUG_PAYPAL_ADAPTIVE_OPTIONS"), $this->debugType, $options->toArray()) : null;
     $adaptive = new Prism\Payment\PayPal\Adaptive($apiUrl, $options);
     $adaptive->setTransport($http);
     $response = $adaptive->doPreppproval();
     // DEBUG DATA
     JDEBUG ? $this->log->add(JText::_($this->textPrefix . "_DEBUG_PAYPAL_ADAPTIVE_RESPONSE"), $this->debugType, $response) : null;
     $preapprovalKey = $response->getPreApprovalKey();
     if (!$preapprovalKey) {
         return null;
     }
     // Store token to the payment session.
     $paymentSession->setUniqueKey($preapprovalKey);
     $paymentSession->storeUniqueKey();
     // Get paypal checkout URL.
     if (!$this->params->get('paypal_sandbox', 1)) {
         $output["redirect_url"] = $this->params->get("paypal_url") . "?cmd=_ap-preapproval&preapprovalkey=" . rawurlencode($preapprovalKey);
     } else {
         $output["redirect_url"] = $this->params->get("paypal_sandbox_url") . "?cmd=_ap-preapproval&preapprovalkey=" . rawurlencode($preapprovalKey);
     }
     return $output;
 }