Example #1
0
function moveToCourseFromWaitingList($course_id)
{
    $dbo =& JFactory::getDbo();
    $query = "SELECT * FROM `#__lms_courses` WHERE id = '{$course_id}' AND self_reg != '0'  ";
    $dbo->setQuery($query);
    $course = $dbo->loadObject();
    $params = new JLMSParameters($course->params);
    $max_attendees = $params->get('max_attendees', 0);
    //count users in course
    $query = "SELECT COUNT(DISTINCT(user_id)) FROM `#__lms_users_in_groups` WHERE course_id = {$course_id}";
    // AND role_id = 2";
    $dbo->setQuery($query);
    $current_attendees = $dbo->loadResult();
    $limit = $max_attendees - $current_attendees;
    //course full - return true
    if ($limit <= 0) {
        return false;
    }
    $query = "SELECT user_id FROM #__lms_waiting_lists WHERE course_id={$course_id} ORDER BY ordering ASC";
    $dbo->setQuery($query, 0, $limit);
    $ids = $dbo->loadResultArray();
    $query = "DELETE FROM #__lms_waiting_lists WHERE course_id={$course_id} AND user_id IN (" . implode(',', $ids) . ")";
    $dbo->setQuery($query);
    $dbo->query();
    $result = array();
    $query = "INSERT INTO `#__lms_users_in_groups` ( course_id , user_id, enrol_time ) VALUES ";
    $first = true;
    foreach ($ids as $id) {
        $query .= !$first ? ',' : '';
        $query .= "\n({$course_id}, {$id}, '" . JLMS_gmdate() . "')";
        $first = false;
        $tmp = new stdClass();
        $tmp->user_id = $id;
        $tmp->course_id = $course_id;
        $result[] = $tmp;
    }
    $dbo->setQuery($query);
    $dbo->query();
    if (!count($result)) {
        return false;
    }
    return $result;
}
Example #2
0
 function validate_recurrent_subscription($proc)
 {
     global $Itemid, $JLMS_CONFIG, $JLMS_DB;
     $params = new JLMSParameters($proc->params);
     // post back to PayPal system to validate
     /*
     foreach ($_POST as $key=>$value) $postdata.=$key."=".urlencode($value)."&";	
     $server_url2 = str_replace('https://','',str_replace('/cgi-bin/webscr','', $params->get( 'server_url' ) ));
     $curl = curl_init('https://'.$server_url2.'/cgi-bin/webscr');
     curl_setopt ($curl, CURLOPT_HEADER, 0);
     curl_setopt ($curl, CURLOPT_POST, 1);
     curl_setopt ($curl, CURLOPT_POSTFIELDS, $postdata);
     curl_setopt ($curl, CURLOPT_SSL_VERIFYPEER, 0);
     //curl_setopt ($curl, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt ($curl, CURLOPT_SSL_VERIFYHOST, 1);  
     $response = curl_exec ($curl);  	
     curl_close ($curl);
     */
     $req = 'cmd=_notify-validate';
     foreach ($_POST as $key => $value) {
         $value = urlencode(stripslashes($value));
         $req .= "&{$key}={$value}";
     }
     // post back to PayPal system to validate
     $server_url2 = str_replace('https://', '', str_replace('/cgi-bin/webscr', '', $params->get('server_url')));
     $header = "POST /cgi-bin/webscr HTTP/1.0\r\n";
     $header .= "Host: " . $server_url2 . "\r\n";
     $header .= "Content-Type: application/x-www-form-urlencoded\r\n";
     $header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
     $fp = fsockopen($server_url2, 80, $errno, $errstr, 30);
     $verifed = false;
     if (!$fp) {
         die;
     } else {
         fputs($fp, $header . $req);
         while (!feof($fp)) {
             $res_pp = fgets($fp, 1024);
             if (strcmp($res_pp, "VERIFIED") == 0) {
                 $verifed = true;
             }
         }
         fclose($fp);
     }
     if (!$verifed) {
         die;
     }
     //if ($response != "VERIFIED") die("You should not do that ...");
     //mosMail( '*****@*****.**', 'LMS Trial', '*****@*****.**', 'Paypal', $server_url2, false, NULL, NULL );
     // assign posted variables to local variables
     // assign posted variables to local variables
     $item_name = mosGetParam($_POST, 'item_name', 0);
     $item_number = mosGetParam($_POST, 'item_number', '');
     $payment_status = mosGetParam($_POST, 'payment_status', '');
     $payment_amount = mosGetParam($_POST, 'mc_gross', '');
     $payment_currency = mosGetParam($_POST, 'mc_currency', '');
     $txn_id = mosGetParam($_POST, 'txn_id', '');
     $receiver_email = mosGetParam($_POST, 'receiver_email', '');
     $business = mosGetParam($_POST, 'business', '');
     $payer_email = mosGetParam($_POST, 'payer_email', '');
     $payment_date = mosGetParam($_POST, 'payment_date', '');
     $subscr_date = mosGetParam($_POST, 'subscr_date', '');
     $mc_gross = mosGetParam($_POST, 'mc_gross', '');
     //amount
     $mc_fee = mosGetParam($_POST, 'mc_fee', '');
     $txn_type = mosGetParam($_POST, 'txn_type', '');
     $subscr_id = mosGetParam($_POST, 'subscr_id', '');
     $subscr_date = mosGetParam($_POST, 'subscr_date', '');
     $recurring = mosGetParam($_POST, 'recurring', '');
     $recur_times = mosGetParam($_POST, 'recur_times', '');
     $reattempt = mosGetParam($_POST, 'reattempt', '');
     $period1 = mosGetParam($_POST, 'period1', '');
     $period2 = mosGetParam($_POST, 'period2', '');
     $period3 = mosGetParam($_POST, 'period3', '');
     $amount1 = mosGetParam($_POST, 'amount1', '');
     $amount2 = mosGetParam($_POST, 'amount2', '');
     $amount3 = mosGetParam($_POST, 'amount3', '');
     $mc_amount1 = mosGetParam($_POST, 'mc_amount1', '');
     $mc_amount2 = mosGetParam($_POST, 'mc_amount2', '');
     $mc_amount3 = mosGetParam($_POST, 'mc_amount3', '');
     $tax_amount = isset($_POST['option_selection1']) ? $_POST['option_selection1'] : 0;
     $tax_paypal = isset($_POST['tax']) ? $_POST['tax'] : 0;
     if ($JLMS_CONFIG->get('debug_mode', false)) {
         jimport('joomla.error.log');
         $log =& JLog::getInstance('payments.log');
         ob_start();
         var_dump($_REQUEST);
         $content = ob_get_contents();
         ob_end_clean();
         $entry['COMMENT'] = $content;
         $log->addEntry($entry);
     }
     require_once _JOOMLMS_FRONT_HOME . '/includes/joomla_lms.subscription.lib.php';
     if ($receiver_email != $params->get('business_email') && $business != $params->get('business_email')) {
         die;
     }
     if ($payment_currency != $JLMS_CONFIG->get('jlms_cur_code')) {
         die;
     }
     // new subscription
     if ($txn_type == 'subscr_signup') {
         $query = "SELECT * FROM #__lms_payments_checksum WHERE payment_id = " . $item_number;
         $JLMS_DB->setQuery($query);
         $checksum = $JLMS_DB->loadObject();
         if (!$checksum->a1 && $checksum->p1 || !$checksum->a2 && $checksum->p2) {
             $query = "SELECT * FROM `#__lms_payments` WHERE id = {$item_number}";
             $JLMS_DB->setQuery($query);
             $payment_info = $JLMS_DB->loadObject();
             $subscr_date_obj = JFactory::getDate($subscr_date);
             $subscr_date_mysql = $subscr_date_obj->toMySQL();
             jlms_update_payment($item_number, $txn_id, 'Completed', $subscr_date_mysql, $tax_amount + $tax_paypal, $tax_paypal, $isReccuring = true);
             jlms_register_new_user($item_number);
             if ($checksum->a2) {
                 $next_amount = $checksum->a2;
             } else {
                 if ($checksum->a3) {
                     $next_amount = $checksum->a3;
                 }
             }
             if ($next_amount) {
                 $parent_id = $payment_info->parent_id ? $payment_info->parent_id : $payment_info->id;
                 $query = "INSERT INTO `#__lms_payments` SET txn_id = '', status = 'Pending', tax_amount = '{$tax_amount}', tax2_amount = '{$tax2_amount}', date ='" . JLMS_gmdate() . "', parent_id = '{$parent_id}', amount = '{$next_amount}', cur_code = '{$payment_info->cur_code}', user_id = {$payment_info->user_id}, payment_type = '{$payment_info->payment_type}', sub_id = '{$payment_info->sub_id}', proc_id = '{$payment_info->proc_id}', processor = '{$payment_info->processor}'";
                 $JLMS_DB->setQuery($query);
                 $JLMS_DB->query();
             }
         }
         //get plan_id
         /*$query = "SELECT status FROM `#__lms_payments` WHERE id = $item_number ";
         		$JLMS_DB->setQuery($query);
         		$prev_payment = $JLMS_DB->LoadResult();
         		*/
         //jlms_update_payment( $item_number, $txn_id, 'Completed', $payment_date, $tax_amount, 0, $isReccuring = false );
         //jlms_register_new_user( $item_number );
     } else {
         if ($txn_type == 'subscr_payment') {
             //mosMail( '*****@*****.**', 'LMS Trial', '*****@*****.**', 'Paypal', $payment_status, false, NULL, NULL );
             //if ( $payment_status != 'Completed' ) { die; }
             if ($txn_id) {
                 $query = "SELECT count(1) FROM `#__lms_payments` WHERE txn_id = " . $JLMS_DB->quote($txn_id);
                 $JLMS_DB->setQuery($query);
                 $txt_id_exists = $JLMS_DB->loadResult();
                 if ($txt_id_exists) {
                     die;
                 }
             }
             $query = "SELECT p.id, p.name, p.description, p.published, p.p1, p.t1, p.p2, p.t2, p.p3, p.t3, s.a1, s.a2, s.a3, p.sra, p.src, p.srt, p.params" . "\n FROM #__lms_payment_items pi," . "\n #__lms_subscriptions s," . "\n #__lms_plans_subscriptions ps," . "\n #__lms_plans p" . "\n WHERE pi.payment_id=" . $item_number . "\n AND pi.item_id=s.id" . "\n AND ps.subscr_id=s.id" . "\n AND p.id=ps.plan_id";
             $JLMS_DB->setQuery($query);
             $plan = $JLMS_DB->loadObject();
             if (empty($plan)) {
                 die;
             }
             // checking if subscription data exists
             $query = "SELECT * FROM #__lms_payments_checksum WHERE payment_id = " . $item_number;
             $JLMS_DB->setQuery($query);
             $checksum = $JLMS_DB->loadObject();
             if (empty($checksum)) {
                 die;
             }
             $query = "SELECT * FROM `#__lms_payments` WHERE (id = {$item_number} OR parent_id = {$item_number}) AND status != 'Completed' AND amount = '" . ($mc_gross - $tax_paypal) . "' ORDER BY id DESC LIMIT 1";
             $JLMS_DB->setQuery($query);
             $payment_info = $JLMS_DB->loadObject();
             if (empty($payment_info)) {
                 die;
             }
             jlms_update_payment($payment_info->id, $txn_id, $payment_status, $payment_date, $tax_amount + $tax_paypal, $tax_paypal, $isReccuring = true);
             if ($payment_status == 'Completed' && $checksum->a3) {
                 $next_amount = 0;
                 if (!$payment_info->parent_id && $checksum->a2) {
                     $next_amount = $checksum->a2;
                 } else {
                     $next_amount = $checksum->a3;
                 }
                 if ($next_amount) {
                     $parent_id = $payment_info->parent_id ? $payment_info->parent_id : $payment_info->id;
                     $query = "INSERT INTO `#__lms_payments` SET txn_id = '', status = 'Pending', tax_amount = '{$tax_amount}', tax2_amount = '{$tax2_amount}', date ='" . JLMS_gmdate() . "', parent_id = '{$parent_id}', amount = '{$next_amount}', cur_code = '{$payment_info->cur_code}', user_id = {$payment_info->user_id}, payment_type = '{$payment_info->payment_type}', sub_id = '{$payment_info->sub_id}', proc_id = '{$payment_info->proc_id}', processor = '{$payment_info->processor}'";
                     $JLMS_DB->setQuery($query);
                     $JLMS_DB->query();
                 }
                 jlms_register_new_user($item_number);
             }
             $user_id = $payment_info->user_id;
         } else {
             if ($txn_type == 'subscr_cancel' || $txn_type == 'subscr_eot') {
                 if ($txn_type == 'subscr_cancel') {
                     $query = "SELECT *  FROM `#__lms_payments` WHERE (id = {$item_number} OR parent_id = {$item_number}) AND status != 'Completed' ORDER BY id DESC LIMIT 1";
                     $JLMS_DB->setQuery($query);
                     $payment_info = $JLMS_DB->loadObject();
                     if (is_object($payment_info)) {
                         $query = "UPDATE `#__lms_payments` SET status = 'Canceled' WHERE id = " . $JLMS_DB->quote($payment_info->id);
                         $JLMS_DB->setQuery($query);
                         $JLMS_DB->Query();
                     }
                 }
                 jlms_register_new_user($item_number, 1);
             }
         }
     }
     if ($payment_info->id) {
         return $payment_info->id;
     } else {
         return $item_number;
     }
     //}
     //fclose ($fp);
     //}
 }