Example #1
0
 function process()
 {
     global $option, $Itemid;
     // This function actually processes the payment.  This function will
     // load the $response array with all the returned information.  The return
     // values for the function are:
     // 1 - Approved
     // 2 - Declined
     // 3 - Error
     // construct the fields string to pass to authorize.net
     foreach ($this->fields as $key => $value) {
         //$this->field_string .= "$key=" . urlencode( $value ) . "&";
         // 29.11.2007 (DEN) - bug withprinting customer emails at the Authorize side (double urlencode!)
         $this->field_string .= "{$key}=" . $value . "&";
     }
     // execute the HTTPS post via CURL
     if (function_exists('curl_init')) {
         $ch = curl_init($this->gateway_url);
         curl_setopt($ch, CURLOPT_HEADER, 0);
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
         curl_setopt($ch, CURLOPT_POSTFIELDS, rtrim($this->field_string, "& "));
     } else {
         JLMSRedirect(sefRelToAbs('index.php?option=' . $option . '&task=subscription&Itemid=' . $Itemid), 'This payment type is not supported by server.');
     }
     //curl_setopt ($ch, CURLOPT_HTTPPROXYTUNNEL, TRUE);
     //curl_setopt ($ch, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
     //curl_setopt ($ch, CURLOPT_PROXY,"http://proxy.shr.secureserver.net:3128");
     //curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
     $this->response_string = urldecode(curl_exec($ch));
     if (curl_errno($ch)) {
         $this->response['Response Reason Text'] = curl_error($ch);
         return 3;
     } else {
         curl_close($ch);
     }
     // load a temporary array with the values returned from authorize.net
     $temp_values = explode('|', $this->response_string);
     // load a temporary array with the keys corresponding to the values
     // returned from authorize.net (taken from AIM documentation)
     $temp_keys = array("Response Code", "Response Subcode", "Response Reason Code", "Response Reason Text", "Approval Code", "AVS Result Code", "Transaction ID", "Invoice Number", "Description", "Amount", "Method", "Transaction Type", "Customer ID", "Cardholder First Name", "Cardholder Last Name", "Company", "Billing Address", "City", "State", "Zip", "Country", "Phone", "Fax", "Email", "Ship to First Name", "Ship to Last Name", "Ship to Company", "Ship to Address", "Ship to City", "Ship to State", "Ship to Zip", "Ship to Country", "Tax Amount", "Duty Amount", "Freight Amount", "Tax Exempt Flag", "PO Number", "MD5 Hash", "Card Code (CVV2/CVC2/CID) Response Code", "Cardholder Authentication Verification Value (CAVV) Response Code");
     // add additional keys for reserved fields and merchant defined fields
     for ($i = 0; $i <= 27; $i++) {
         array_push($temp_keys, 'Reserved Field ' . $i);
     }
     $i = 0;
     while (sizeof($temp_keys) < sizeof($temp_values)) {
         array_push($temp_keys, 'Merchant Defined Field ' . $i);
         $i++;
     }
     // combine the keys and values arrays into the $response array.  This
     // can be done with the array_combine() function instead if you are using
     // php 5.
     for ($i = 0; $i < sizeof($temp_values); $i++) {
         $this->response["{$temp_keys[$i]}"] = $temp_values[$i];
     }
     // Return the response code.
     return $this->response['Response Code'];
 }
function JLMS_changeLink($option)
{
    global $JLMS_DB, $my, $Itemid, $JLMS_CONFIG;
    $course_id = $JLMS_CONFIG->get('course_id');
    $JLMS_ACL =& JLMSFactory::getACL();
    if ($course_id && $JLMS_ACL->CheckPermissions('links', 'publish')) {
        $state = intval(mosGetParam($_REQUEST, 'state', 0));
        if ($state != 1) {
            $state = 0;
        }
        $cid = mosGetParam($_REQUEST, 'cid', array(0));
        $cid2 = intval(mosGetParam($_REQUEST, 'cid2', 0));
        if ($cid2) {
            $cid = array();
            $cid[] = $cid2;
        }
        if (!is_array($cid)) {
            $cid = array(0);
        }
        if (!is_array($cid) || count($cid) < 1) {
            $action = 1 ? 'Publish' : 'Unpublish';
            echo "<script> alert('Select an item to {$action}'); window.history.go(-1);</script>\n";
            exit;
        }
        $cids = implode(',', $cid);
        $query = "UPDATE #__lms_links" . "\n SET published = {$state}" . "\n WHERE id IN ( {$cids} ) AND course_id = {$course_id}" . ($JLMS_ACL->CheckPermissions('links', 'only_own_items') ? " AND owner_id = '" . $my->id . "'" : '');
        $JLMS_DB->setQuery($query);
        if (!$JLMS_DB->query()) {
            echo "<script> alert('" . $JLMS_DB->getErrorMsg() . "'); window.history.go(-1); </script>\n";
            exit;
        }
    }
    JLMSRedirect(sefRelToAbs("index.php?option={$option}&Itemid={$Itemid}&task=links&id={$course_id}"));
}
function JLMS_del_notice_no_ajax($option)
{
    global $JLMS_CONFIG, $my, $JLMS_DB, $Itemid;
    $cid = mosGetParam($_REQUEST, 'cid', array(0));
    $ntask = strval(mosGetParam($_REQUEST, 'ntask', ''));
    $doc_id = intval(mosGetParam($_REQUEST, 'doc_id', 0));
    $course_id = intval(mosGetParam($_REQUEST, 'course_id', 0));
    $v_id = intval(mosGetParam($_REQUEST, 'v_id', 0));
    $query = "DELETE FROM #__lms_page_notices WHERE id IN (" . implode(",", $cid) . ") AND usr_id = " . $my->id;
    $JLMS_DB->setQuery($query);
    $JLMS_DB->query();
    JLMSRedirect(sefRelToAbs("index.php?option={$option}&Itemid={$Itemid}&task=view_all_notices"));
}
Example #4
0
 function JLMS_saveCertificate($course_id, $option, $crtf_type, $redirect_url = '')
 {
     global $my, $JLMS_DB, $Itemid;
     $JLMS_ACL =& JLMSFactory::getACL();
     $crtf_id = 0;
     /*echo '<pre>';
     	print_r($_REQUEST);*/
     if ($course_id && $JLMS_ACL->CheckPermissions('docs', 'view')) {
         $crtf_name = isset($_REQUEST['crtf_name']) ? $_REQUEST['crtf_name'] : '';
         $crtf_name = get_magic_quotes_gpc() ? stripslashes($crtf_name) : $crtf_name;
         $crtf_name = ampReplace(strip_tags($crtf_name));
         $crtf_name = $JLMS_DB->GetEscaped($crtf_name);
         $crtf_text = isset($_REQUEST['crtf_text']) ? $_REQUEST['crtf_text'] : '';
         $crtf_text = get_magic_quotes_gpc() ? stripslashes($crtf_text) : $crtf_text;
         $crtf_text = ampReplace(strip_tags($crtf_text));
         $crtf_text = $JLMS_DB->GetEscaped($crtf_text);
         $crtf_align = intval(mosGetParam($_REQUEST, 'crtf_align', 0));
         $published = intval(mosGetParam($_REQUEST, 'published', 1));
         $crtf_shadow = intval(mosGetParam($_REQUEST, 'crtf_shadow', 0));
         $crtf_font = strval(mosGetParam($_REQUEST, 'crtf_font', 0));
         if (!preg_match("/^[a-zA-Z0-9\\-\\_\\s]+\\.ttf\$/", $crtf_font)) {
             $crtf_font = 'arial.ttf';
         }
         if ($crtf_shadow) {
             $crtf_shadow = 1;
         }
         if (!in_array($crtf_align, array(0, 1, 2))) {
             $crtf_align = 0;
         }
         $text_x = intval(mosGetParam($_REQUEST, 'text_x', 0));
         $text_y = intval(mosGetParam($_REQUEST, 'text_y', 0));
         $text_size = intval(mosGetParam($_REQUEST, 'text_size', 0));
         $new_file = false;
         $file_id = 0;
         if (isset($_FILES['userfile']) && !empty($_FILES['userfile']['name'])) {
             $file_id = JLMS_uploadFile($course_id);
             $new_file = true;
         }
         $add_query = '';
         $crtf_id = 0;
         if ($crtf_type == 2) {
             $crtf_id = intval(mosGetParam($_REQUEST, 'crtf_id', 0));
             $add_query = " AND id = '" . $crtf_id . "'";
         }
         $query = "SELECT * FROM #__lms_certificates WHERE course_id = '" . $course_id . "' AND crtf_type = '" . $crtf_type . "' AND parent_id = 0" . $add_query;
         $JLMS_DB->SetQuery($query);
         $old_crt = $JLMS_DB->LoadObjectList();
         if (count($old_crt)) {
             $old_file = $old_crt[0]->file_id;
             if ($old_file && $new_file) {
                 $files = array();
                 $files[] = $old_file;
                 JLMS_deleteFiles($files);
             }
             $crtf_id = $old_crt[0]->id;
             $query = "UPDATE #__lms_certificates SET published = {$published}, crtf_name = '" . $crtf_name . "', crtf_text = '" . $crtf_text . "', crtf_align = {$crtf_align}, crtf_shadow = {$crtf_shadow}, text_x = '" . $text_x . "', text_y = '" . $text_y . "', text_size = '" . $text_size . "', crtf_font = " . $JLMS_DB->quote($crtf_font) . "" . ($new_file ? ", file_id = '" . $file_id . "'" : '') . " WHERE course_id = '" . $course_id . "' AND crtf_type = '" . $crtf_type . "' AND parent_id = 0" . $add_query;
             $JLMS_DB->SetQuery($query);
             $JLMS_DB->query();
         } else {
             $query = "INSERT INTO #__lms_certificates (parent_id, course_id, published, crtf_name, crtf_text, crtf_align, crtf_shadow, text_x, text_y, text_size" . ($new_file ? ", file_id" : '') . ", crtf_type, crtf_font) VALUES ( 0, '" . $course_id . "', '" . $published . "', '" . $crtf_name . "', '" . $crtf_text . "', {$crtf_align}, {$crtf_shadow}, '" . $text_x . "', '" . $text_y . "', '" . $text_size . "'" . ($new_file ? ",'" . $file_id . "'" : '') . ", '" . $crtf_type . "', " . $JLMS_DB->quote($crtf_font) . ")";
             $JLMS_DB->SetQuery($query);
             $JLMS_DB->query();
             $crtf_id = $JLMS_DB->insertid();
         }
         $crtf_id = intval($crtf_id);
         /* 23 october 2007 - (DEN) */
         /* handle custom text fields */
         $ctxt_mes_ids = josGetArrayInts('ctxt_mes_id', $_REQUEST);
         $ctxt_mes_text = isset($_REQUEST['ctxt_mes_text']) ? $_REQUEST['ctxt_mes_text'] : array();
         $ctxt_mes_shadow_hid = mosGetParam($_REQUEST, 'ctxt_mes_shadow_hid', array());
         $ctxt_mes_x = mosGetParam($_REQUEST, 'ctxt_mes_x', array());
         $ctxt_mes_y = mosGetParam($_REQUEST, 'ctxt_mes_y', array());
         $ctxt_mes_h = mosGetParam($_REQUEST, 'ctxt_mes_h', array());
         $ctxt_mes_font = mosGetParam($_REQUEST, 'ctxt_mes_font', array());
         $p_ids = array();
         $i = 0;
         $add_cmes_ids = array();
         /*print_r($ctxt_mes_ids);*/
         foreach ($ctxt_mes_ids as $cmid) {
             if (isset($ctxt_mes_text[$i]) && isset($ctxt_mes_x[$i]) && isset($ctxt_mes_y[$i]) && isset($ctxt_mes_h[$i]) && isset($ctxt_mes_font[$i]) && isset($ctxt_mes_shadow_hid[$i]) && $ctxt_mes_text[$i]) {
                 $crtf_shadow = $ctxt_mes_shadow_hid[$i] ? 1 : 0;
                 $crtf_font = '';
                 $text_x = intval($ctxt_mes_x[$i]);
                 if ($text_x < 0) {
                     $text_x = 0;
                 }
                 $text_y = intval($ctxt_mes_y[$i]);
                 if ($text_y < 0) {
                     $text_y = 0;
                 }
                 $text_size = intval($ctxt_mes_h[$i]);
                 if ($text_size < 0) {
                     $text_size = 0;
                 }
                 $crtf_text = $ctxt_mes_text[$i];
                 $crtf_text = get_magic_quotes_gpc() ? stripslashes($crtf_text) : $crtf_text;
                 $crtf_text = ampReplace(strip_tags($crtf_text));
                 $crtf_text = $JLMS_DB->GetEscaped($crtf_text);
                 $crtf_font = strval($ctxt_mes_font[$i]);
                 if (!preg_match("/^[a-zA-Z0-9\\-\\_\\s]+\\.ttf\$/", $crtf_font)) {
                     $crtf_font = 'arial.ttf';
                 }
                 if (!$cmid) {
                     $query = "INSERT INTO #__lms_certificates (parent_id, course_id, crtf_name, crtf_text, crtf_align, crtf_shadow, text_x, text_y, text_size, crtf_type, crtf_font) VALUES ( {$crtf_id}, '" . $course_id . "', '', '" . $crtf_text . "', " . $i . ", {$crtf_shadow}, '" . $text_x . "', '" . $text_y . "', '" . $text_size . "', '-2', " . $JLMS_DB->quote($crtf_font) . ")";
                     $JLMS_DB->SetQuery($query);
                     $JLMS_DB->query();
                     $crtf_cmes_id = $JLMS_DB->insertid();
                     /*echo $JLMS_DB->geterrormsg();*/
                     $add_cmes_ids[] = $crtf_cmes_id;
                 } else {
                     $query = "UPDATE #__lms_certificates SET crtf_text = '" . $crtf_text . "', crtf_align = {$i}, crtf_shadow = {$crtf_shadow}, text_x = '" . $text_x . "', text_y = '" . $text_y . "', text_size = '" . $text_size . "', crtf_font = " . $JLMS_DB->quote($crtf_font) . " WHERE course_id = '" . $course_id . "' AND crtf_type = '-2' AND parent_id = {$crtf_id} AND id = {$cmid}";
                     $JLMS_DB->SetQuery($query);
                     $JLMS_DB->query();
                     $add_cmes_ids[] = $cmid;
                 }
             }
             $i++;
         }
         if (empty($add_cmes_ids)) {
             $add_cmes_ids = array(0);
         }
         /*print_r($add_cmes_ids);*/
         $add_cmes_ids_t = implode(',', $add_cmes_ids);
         $query = "DELETE FROM #__lms_certificates WHERE course_id = {$course_id} AND parent_id = {$crtf_id} AND crtf_type = '-2' AND id NOT IN ({$add_cmes_ids_t})";
         $JLMS_DB->SetQuery($query);
         $JLMS_DB->query();
         /*die;*/
         /* end of 'custom text fields' mod */
         if ($crtf_id) {
             $JLMS_ACL =& JLMSFactory::getACL();
             $lroles = $JLMS_ACL->GetSystemRolesIds(1);
             $add_certificates = josGetArrayInts('certificate_types', $_REQUEST);
             $types = array();
             if (!empty($add_certificates)) {
                 foreach ($add_certificates as $add_cert) {
                     if ($add_cert && in_array($add_cert, $lroles)) {
                         $certificate_default = intval(mosGetParam($_REQUEST, 'certificate_default_' . $add_cert, 0));
                         if (!$certificate_default) {
                             $crtf_text = isset($_REQUEST['crtf_text_' . $add_cert]) ? $_REQUEST['crtf_text_' . $add_cert] : '';
                             $crtf_text = get_magic_quotes_gpc() ? stripslashes($crtf_text) : $crtf_text;
                             $crtf_text = ampReplace(strip_tags($crtf_text));
                             $crtf_text = $JLMS_DB->GetEscaped($crtf_text);
                             $crtf_align = intval(mosGetParam($_REQUEST, 'crtf_align_' . $add_cert, 0));
                             $crtf_shadow = intval(mosGetParam($_REQUEST, 'crtf_shadow_' . $add_cert, 0));
                             $crtf_font = strval(mosGetParam($_REQUEST, 'crtf_font_' . $add_cert, 0));
                             if (!preg_match("/^[a-zA-Z0-9\\-\\_\\s]+\\.ttf\$/", $crtf_font)) {
                                 $crtf_font = 'arial.ttf';
                             }
                             if ($crtf_shadow) {
                                 $crtf_shadow = 1;
                             }
                             if (!in_array($crtf_align, array(0, 1, 2))) {
                                 $crtf_align = 0;
                             }
                             $text_x = intval(mosGetParam($_REQUEST, 'text_x_' . $add_cert, 0));
                             $text_y = intval(mosGetParam($_REQUEST, 'text_y_' . $add_cert, 0));
                             $text_size = intval(mosGetParam($_REQUEST, 'text_size_' . $add_cert, 0));
                             $new_file = false;
                             $file_id = 0;
                             if (isset($_FILES['userfile_' . $add_cert]) && !empty($_FILES['userfile_' . $add_cert]['name'])) {
                                 $file_id = JLMS_uploadFile($course_id, 'userfile_' . $add_cert);
                                 $new_file = true;
                             }
                             $query = "SELECT * FROM #__lms_certificates WHERE course_id = '" . $course_id . "' AND crtf_type = '" . $add_cert . "' AND parent_id = {$crtf_id}";
                             $JLMS_DB->SetQuery($query);
                             $old_crt = $JLMS_DB->LoadObjectList();
                             if (count($old_crt)) {
                                 $old_file = $old_crt[0]->file_id;
                                 if ($old_file && $new_file) {
                                     $files = array();
                                     $files[] = $old_file;
                                     JLMS_deleteFiles($files);
                                 }
                                 $crtf_id_c = $old_crt[0]->id;
                                 $query = "UPDATE #__lms_certificates SET crtf_name = '" . $crtf_name . "', crtf_text = '" . $crtf_text . "', crtf_align = {$crtf_align}, crtf_shadow = {$crtf_shadow}, text_x = '" . $text_x . "', text_y = '" . $text_y . "', text_size = '" . $text_size . "', crtf_font = " . $JLMS_DB->quote($crtf_font) . "" . ($new_file ? ", file_id = '" . $file_id . "'" : '') . " WHERE course_id = '" . $course_id . "' AND crtf_type = '" . $add_cert . "' AND parent_id = {$crtf_id}";
                                 $JLMS_DB->SetQuery($query);
                                 $JLMS_DB->query();
                             } else {
                                 $query = "INSERT INTO #__lms_certificates (parent_id, course_id, crtf_name, crtf_text, crtf_align, crtf_shadow, text_x, text_y, text_size" . ($new_file ? ", file_id" : '') . ", crtf_type, crtf_font) VALUES ( {$crtf_id}, '" . $course_id . "', '" . $crtf_name . "', '" . $crtf_text . "', {$crtf_align}, {$crtf_shadow}, '" . $text_x . "', '" . $text_y . "', '" . $text_size . "'" . ($new_file ? ",'" . $file_id . "'" : '') . ", '" . $add_cert . "', " . $JLMS_DB->quote($crtf_font) . ")";
                                 $JLMS_DB->SetQuery($query);
                                 $JLMS_DB->query();
                                 $crtf_id_c = $JLMS_DB->insertid();
                             }
                             /* 23 october 2007 - (DEN) */
                             /* handle custom text fields */
                             $ctxt_mes_ids = josGetArrayInts('ctxt_mes_id_' . $add_cert, $_REQUEST);
                             $ctxt_mes_text = isset($_REQUEST['ctxt_mes_text_' . $add_cert]) ? $_REQUEST['ctxt_mes_text_' . $add_cert] : array();
                             $ctxt_mes_shadow_hid = mosGetParam($_REQUEST, 'ctxt_mes_shadow_hid_' . $add_cert, array());
                             $ctxt_mes_x = mosGetParam($_REQUEST, 'ctxt_mes_x_' . $add_cert, array());
                             $ctxt_mes_y = mosGetParam($_REQUEST, 'ctxt_mes_y_' . $add_cert, array());
                             $ctxt_mes_h = mosGetParam($_REQUEST, 'ctxt_mes_h_' . $add_cert, array());
                             $ctxt_mes_font = mosGetParam($_REQUEST, 'ctxt_mes_font_' . $add_cert, array());
                             $p_ids = array();
                             $i = 0;
                             $add_cmes_ids = array();
                             foreach ($ctxt_mes_ids as $cmid) {
                                 if (isset($ctxt_mes_text[$i]) && isset($ctxt_mes_x[$i]) && isset($ctxt_mes_y[$i]) && isset($ctxt_mes_h[$i]) && isset($ctxt_mes_font[$i]) && isset($ctxt_mes_shadow_hid[$i]) && $ctxt_mes_text[$i]) {
                                     $crtf_shadow = $ctxt_mes_shadow_hid[$i] ? 1 : 0;
                                     $crtf_font = '';
                                     $text_x = intval($ctxt_mes_x[$i]);
                                     if ($text_x < 0) {
                                         $text_x = 0;
                                     }
                                     $text_y = intval($ctxt_mes_y[$i]);
                                     if ($text_y < 0) {
                                         $text_y = 0;
                                     }
                                     $text_size = intval($ctxt_mes_h[$i]);
                                     if ($text_size < 0) {
                                         $text_size = 0;
                                     }
                                     $crtf_text = $ctxt_mes_text[$i];
                                     $crtf_text = get_magic_quotes_gpc() ? stripslashes($crtf_text) : $crtf_text;
                                     $crtf_text = ampReplace(strip_tags($crtf_text));
                                     $crtf_text = $JLMS_DB->GetEscaped($crtf_text);
                                     $crtf_font = strval($ctxt_mes_font[$i]);
                                     if (!preg_match("/^[a-zA-Z0-9\\-\\_\\s]+\\.ttf\$/", $crtf_font)) {
                                         $crtf_font = 'arial.ttf';
                                     }
                                     if (!$cmid) {
                                         $query = "INSERT INTO #__lms_certificates (parent_id, course_id, crtf_name, crtf_text, crtf_align, crtf_shadow, text_x, text_y, text_size, crtf_type, crtf_font) VALUES ( {$crtf_id_c}, '" . $course_id . "', '', '" . $crtf_text . "', " . $i . ", {$crtf_shadow}, '" . $text_x . "', '" . $text_y . "', '" . $text_size . "', '-2', " . $JLMS_DB->quote($crtf_font) . ")";
                                         $JLMS_DB->SetQuery($query);
                                         $JLMS_DB->query();
                                         $crtf_cmes_id = $JLMS_DB->insertid();
                                         $add_cmes_ids[] = $crtf_cmes_id;
                                     } else {
                                         $query = "UPDATE #__lms_certificates SET crtf_text = '" . $crtf_text . "', crtf_align = {$i}, crtf_shadow = {$crtf_shadow}, text_x = '" . $text_x . "', text_y = '" . $text_y . "', text_size = '" . $text_size . "', crtf_font = " . $JLMS_DB->quote($crtf_font) . " WHERE course_id = '" . $course_id . "' AND crtf_type = '-2' AND parent_id = {$crtf_id_c} AND id = {$cmid}";
                                         $JLMS_DB->SetQuery($query);
                                         $JLMS_DB->query();
                                         $add_cmes_ids[] = $cmid;
                                     }
                                 }
                                 $i++;
                             }
                             if (empty($add_cmes_ids)) {
                                 $add_cmes_ids = array(0);
                             }
                             $add_cmes_ids_t = implode(',', $add_cmes_ids);
                             $query = "DELETE FROM #__lms_certificates WHERE course_id = {$course_id} AND parent_id = {$crtf_id_c} AND crtf_type = '-2' AND id NOT IN ({$add_cmes_ids_t})";
                             $JLMS_DB->SetQuery($query);
                             $JLMS_DB->query();
                             /* end of 'custom text fields' mod */
                             $types[] = $add_cert;
                         }
                     }
                 }
             }
             if (empty($types)) {
                 $types = array(-2);
             } else {
                 $types[] = -2;
             }
             /*print_r($types);*/
             $types_str = implode(',', $types);
             $query = "SELECT id, file_id FROM #__lms_certificates WHERE course_id = '" . $course_id . "' AND crtf_type NOT IN ({$types_str}) AND parent_id = {$crtf_id}";
             $JLMS_DB->SetQuery($query);
             $old_sec_certs = $JLMS_DB->LoadObjectList();
             $old_files = array();
             $old_sec_cert_ids = array();
             if (!empty($old_sec_certs)) {
                 foreach ($old_sec_certs as $osc) {
                     $old_files[] = $osc->file_id;
                     $old_sec_cert_ids[] = $osc->id;
                 }
                 JLMS_deleteFiles($old_files);
             }
             $query = "DELETE FROM #__lms_certificates WHERE course_id = '" . $course_id . "' AND crtf_type NOT IN ({$types_str}) AND parent_id = {$crtf_id}";
             $JLMS_DB->SetQuery($query);
             $JLMS_DB->query();
             if (!empty($old_sec_cert_ids)) {
                 $osc_t = implode(',', $old_sec_cert_ids);
                 $query = "DELETE FROM #__lms_certificates WHERE course_id = '" . $course_id . "' AND crtf_type = '-2' AND parent_id IN ({$osc_t})";
                 $JLMS_DB->SetQuery($query);
                 $JLMS_DB->query();
             }
         }
     }
     /*die;*/
     if (!$redirect_url) {
         $redirect_url = "index.php?option={$option}&Itemid={$Itemid}&task=gb_certificates&id={$course_id}";
     }
     JLMSRedirect(sefRelToAbs(str_replace('{id}', $crtf_id, $redirect_url)));
 }
function JLMS_viewDRPDescription($id, $option)
{
    global $my, $JLMS_DB, $Itemid;
    $course_id = intval(mosGetParam($_REQUEST, 'course_id', 0));
    //	if ($my->id && $course_id && JLMS_GetUserType($my->id, $course_id) ) {
    $JLMS_ACL =& JLMSFactory::getACL();
    if ($my->id && $course_id && $JLMS_ACL->CheckPermissions('dropbox', 'view')) {
        $query = "SELECT a.*, b.name as owner_username, c.name as recv_username FROM #__lms_dropbox as a, #__users as b, #__users as c" . "\n WHERE a.id = '" . $id . "'" . "\n AND a.course_id = '" . $course_id . "'" . "\n AND a.owner_id = b.id AND a.recv_id = c.id AND (a.owner_id = '" . $my->id . "' OR a.recv_id = '" . $my->id . "')";
        $JLMS_DB->SetQuery($query);
        $dropbox = $JLMS_DB->LoadObjectList();
        if (count($dropbox)) {
            $drop = $dropbox[0];
            $lists = array();
            JLMS_course_dropbox_html::viewDRPDescription($course_id, $option, $drop, $lists);
        } else {
            JLMSRedirect(sefRelToAbs("index.php?option={$option}&Itemid={$Itemid}&task=dropbox&id={$course_id}"));
        }
    } elseif ($course_id) {
        JLMSRedirect(sefRelToAbs("index.php?option={$option}&Itemid={$Itemid}&task=details_course&id={$course_id}"));
    } else {
        JLMSRedirect(sefRelToAbs("index.php?option={$option}&Itemid={$Itemid}"));
    }
}
Example #6
0
 function JQ_FinishQuiz_nojs()
 {
     global $JLMS_DB, $my, $Itemid, $option, $Itemid;
     $ret_str = '';
     $quiz_id = intval(mosGetParam($_REQUEST, 'quiz', 0));
     $id = intval(mosGetParam($_REQUEST, 'id', 0));
     $query = "SELECT * FROM #__lms_quiz_t_quiz WHERE c_id = '" . $quiz_id . "'";
     $JLMS_DB->SetQuery($query);
     $quiz = $JLMS_DB->LoadObjectList();
     if (count($quiz)) {
         $quiz = $quiz[0];
     } else {
         return $ret_str;
     }
     $quiz_params = new JLMSParameters($quiz->params);
     $inside_lp = intval(mosGetParam($_REQUEST, 'inside_lp', 0));
     $QA = new JLMS_quiz_API($quiz_id, $inside_lp);
     if (!$QA->quiz_valid()) {
         return '';
     }
     //		$toolbar_no_a = $QA->quiz_Get_NoAtToolbar();
     $stu_quiz_id = intval(mosGetParam($_REQUEST, 'stu_quiz_id', 0));
     $user_unique_id = strval(mosGetParam($_REQUEST, 'user_unique_id', ''));
     $QA->set('stu_quiz_id', $stu_quiz_id);
     $QA->set('user_unique_id', $user_unique_id);
     $QA->quiz_ProcessStartData();
     if ($QA->start_valid() && $quiz_id) {
         // temporary fo compatibility
         // (25 April 2007 commented) $quiz = $QA->quiz_data;
         //print_r($stu_quiz_id);
         $query = "SELECT SUM(c_score) FROM #__lms_quiz_r_student_question WHERE c_stu_quiz_id = '" . $stu_quiz_id . "'";
         $JLMS_DB->SetQuery($query);
         $user_score = $JLMS_DB->LoadResult();
         if (!$user_score) {
             $user_score = 0;
         }
         /*$query = "SELECT SUM(c_point) FROM #__lms_quiz_t_question WHERE c_quiz_id = '".$quiz_id."'";
         		$JLMS_DB->SetQuery( $query );
         		$max_score = $JLMS_DB->LoadResult();*/
         $max_score = $QA->quiz_Get_MaxScore();
         $nugno_score = $QA->get_qvar('c_passing_score', 0) * $max_score / 100;
         $user_passed = 0;
         if ($user_score >= $nugno_score) {
             $user_passed = 1;
         }
         $user_time = 0;
         $quiz_time1 = time() - date('Z');
         $query = "SELECT c_date_time FROM #__lms_quiz_r_student_quiz WHERE c_id = '" . $stu_quiz_id . "'";
         $JLMS_DB->SetQuery($query);
         $quiz_time2 = $JLMS_DB->LoadResult();
         $quiz_time2a = strtotime($quiz_time2);
         $user_time = $quiz_time1 - $quiz_time2a;
         $query = "UPDATE #__lms_quiz_r_student_quiz SET c_total_score = '" . $user_score . "', c_passed = '" . $user_passed . "', c_total_time = '" . $user_time . "'" . "\n WHERE c_id = '" . $stu_quiz_id . "' and c_quiz_id = '" . $quiz_id . "' and c_student_id = '" . $my->id . "'";
         $JLMS_DB->SetQuery($query);
         $JLMS_DB->query();
         // update lms results
         $lms_course = $QA->get_qvar('course_id', 0);
         $lms_quiz = $quiz_id;
         $lms_user = $my->id;
         $lms_score = $user_score;
         $lms_time = $user_time;
         $lms_date = date('Y-m-d H:i:s', time() - date('Z'));
         $lms_passed = $user_passed;
         global $JLMS_CONFIG;
         if ($lms_course && $JLMS_CONFIG->get('course_id') == $lms_course) {
             $course_params = $JLMS_CONFIG->get('course_params');
             $params = new JLMSParameters($course_params);
             $do_insert_new_res = false;
             if ($params->get('track_type', 0) == 1) {
                 $query = "SELECT * FROM #__lms_quiz_results WHERE course_id = '" . $lms_course . "' AND quiz_id = '" . $lms_quiz . "' AND user_id = '" . $lms_user . "'";
                 $JLMS_DB->SetQuery($query);
                 $old_user_results = $JLMS_DB->LoadObject();
                 if (is_object($old_user_results)) {
                     if (!$lms_passed && !$old_user_results->user_passed && $lms_score > $old_user_results->user_score) {
                         $do_insert_new_res = true;
                     } elseif ($lms_passed && !$old_user_results->user_passed) {
                         $do_insert_new_res = true;
                     } elseif ($lms_passed && $old_user_results->user_passed && $lms_score > $old_user_results->user_score) {
                         $do_insert_new_res = true;
                     } elseif ($lms_passed && $old_user_results->user_passed && $lms_score == $old_user_results->user_score && $lms_time < $old_user_results->user_time) {
                         $do_insert_new_res = true;
                     }
                 } else {
                     $do_insert_new_res = true;
                 }
             } else {
                 $do_insert_new_res = true;
             }
             if ($do_insert_new_res) {
                 $query = "DELETE FROM #__lms_quiz_results WHERE course_id = '" . $lms_course . "' AND quiz_id = '" . $lms_quiz . "' AND user_id = '" . $lms_user . "'";
                 $JLMS_DB->SetQuery($query);
                 $JLMS_DB->query();
                 $query = "INSERT INTO #__lms_quiz_results (course_id, quiz_id, user_id, user_score, quiz_max_score, user_time, quiz_date, user_passed)" . "\n VALUES ('" . $lms_course . "', '" . $lms_quiz . "', '" . $lms_user . "', '" . $lms_score . "', " . intval($max_score) . ", '" . $lms_time . "', '" . $lms_date . "', '" . $lms_passed . "')";
                 $JLMS_DB->SetQuery($query);
                 $JLMS_DB->query();
                 if ($lms_passed) {
                     $db =& JFactory::getDbo();
                     $_JLMS_PLUGINS =& JLMSFactory::getPlugins();
                     //*** send email notifications
                     $JLMS_CONFIG =& JLMSFactory::getConfig();
                     $Itemid = $JLMS_CONFIG->get('Itemid');
                     $e_course = new stdClass();
                     $e_course->course_alias = '';
                     $e_course->course_name = '';
                     $query = "SELECT course_name, name_alias FROM #__lms_courses WHERE id = '" . $lms_course . "'";
                     $db->setQuery($query);
                     $e_course = $db->loadObject();
                     $query = "SELECT c_title FROM #__lms_quiz_t_quiz WHERE c_id = '" . $lms_quiz . "'";
                     $db->setQuery($query);
                     $e_quiz_name = $db->loadResult();
                     $e_user = new stdClass();
                     $e_user->name = '';
                     $e_user->email = '';
                     $e_user->username = '';
                     $query = "SELECT email, name, username FROM #__users WHERE id = '" . $lms_user . "'";
                     $db->setQuery($query);
                     $e_user = $db->loadObject();
                     $e_params['user_id'] = $lms_user;
                     $e_params['course_id'] = $lms_course;
                     $e_params['markers']['{email}'] = $e_user->email;
                     $e_params['markers']['{name}'] = $e_user->name;
                     $e_params['markers']['{username}'] = $e_user->username;
                     $e_params['markers']['{coursename}'] = $e_course->course_name;
                     $e_params['markers']['{quizname}'] = $e_quiz_name;
                     $e_params['markers']['{courselink}'] = JLMSEmailRoute("index.php?option=com_joomla_lms&Itemid={$Itemid}&task=details_course&id={$lms_course}");
                     $e_params['markers_nohtml']['{courselink}'] = $e_params['markers']['{courselink}'];
                     $e_params['markers']['{courselink}'] = '<a href="' . $e_params['markers']['{courselink}'] . '">' . $e_params['markers']['{courselink}'] . '</a>';
                     $e_params['markers']['{lmslink}'] = JLMSEmailRoute("index.php?option=com_joomla_lms&Itemid={$Itemid}");
                     $e_params['markers_nohtml']['{lmslink}'] = $e_params['markers']['{lmslink}'];
                     $e_params['markers']['{lmslink}'] = '<a href="' . $e_params['markers']['{lmslink}'] . '">' . $e_params['markers']['{lmslink}'] . '</a>';
                     $e_params['action_name'] = 'OnQuizCompletion';
                     $_JLMS_PLUGINS->loadBotGroup('emails');
                     $plugin_result_array = $_JLMS_PLUGINS->trigger('OnQuizCompletion', array(&$e_params));
                     //*** end of emails
                 }
             }
         }
         // end of lms results section
     }
     //redirect
     JLMSRedirect(sefRelToAbs("index.php?option={$option}&Itemid={$Itemid}&task=quiz_action&id={$id}&quiz={$quiz_id}&stu_quiz_id={$stu_quiz_id}&user_unique_id={$user_unique_id}&atask=review_stop"));
 }
Example #7
0
function JLMS_showMainPage_front($option)
{
    global $my, $JLMS_DB, $JLMS_CONFIG, $Itemid;
    $JLMS_ACL =& JLMSFactory::getACL();
    $assigned_groups_only = $JLMS_ACL->CheckPermissions('advanced', 'assigned_groups_only');
    $pathway = array();
    $pathway[] = array('name' => _JLMS_PATHWAY_HOME, 'link' => sefRelToAbs("index.php?option={$option}&amp;Itemid={$Itemid}"), 'is_home' => true);
    JLMSAppendPathWay($pathway);
    $hp_items = $JLMS_CONFIG->get('homepage_items');
    $lists = array();
    //courses
    $cidsf = $JLMS_CONFIG->get('student_in_future_courses');
    $course_data_sf = array();
    $cidtxt = '0';
    if (!empty($cidsf)) {
        $cidsfxt = implode(',', $cidsf);
        $query = "SELECT a.*, '0' as user_course_role FROM #__lms_courses as a WHERE a.id IN ({$cidsfxt}) AND a.id NOT IN ({$cidtxt})" . "\n ORDER BY " . ($JLMS_CONFIG->get('lms_courses_sortby', 0) ? "a.ordering, a.course_name, a.id" : "a.course_name, a.ordering, a.id");
        $JLMS_DB->SetQuery($query);
        $course_data_sf = $JLMS_DB->LoadObjectList();
    }
    $my_courses_r = my_courses_r();
    if (count($my_courses_r) || count($cidsf)) {
    } else {
        JLMSRedirect(sefRelToAbs("index.php?option={$option}&Itemid={$Itemid}&task=courses"));
    }
    $c_ids = array();
    foreach ($my_courses_r as $mcr) {
        $c_ids[] = $mcr->id;
    }
    $my_courses_r = array_merge($my_courses_r, $course_data_sf);
    if ($JLMS_CONFIG->get('frontpage_courses_tree', 0)) {
        $hp_items = 999999999;
    }
    $my_courses = array();
    $i = 0;
    while ($i < $hp_items && $i < count($my_courses_r)) {
        $my_courses[] = $my_courses_r[$i];
        $i++;
    }
    if (!is_array($c_ids)) {
        $c_ids = array(0);
    }
    $c_str = implode(',', $c_ids);
    if ($JLMS_CONFIG->get('frontpage_courses_tree', 0)) {
        //My_courses_tree
        $levellimit = 20;
        $query = "SELECT id, c_category as name, parent, 0 as is_course" . "\n FROM #__lms_course_cats ORDER BY c_category";
        $JLMS_DB->setQuery($query);
        $cats = $JLMS_DB->loadObjectList();
        $query = "SELECT a.id as user_certificate, b.course_id" . "\n FROM #__lms_certificate_users as a, #__lms_users_in_groups as b" . "\n WHERE 1" . "\n AND a.user_id = '" . $my->id . "'" . "\n AND a.crt_option = '1'" . "\n AND b.user_id = a.user_id AND a.course_id = b.course_id";
        $JLMS_DB->setQuery($query);
        $crtfs = $JLMS_DB->loadObjectList();
        $i = 0;
        foreach ($my_courses as $course) {
            $my_courses[$i]->certificate = 0;
            foreach ($crtfs as $crtf) {
                if ($course->id == $crtf->course_id && $crtf->user_certificate) {
                    $my_courses[$i]->certificate = 1;
                    break;
                }
            }
            $i++;
        }
        $children = array();
        foreach ($cats as $v) {
            $pt = $v->parent;
            /** Joomla 1.6 compability { */
            $v->parent_id = $v->parent;
            $v->title = $v->name;
            /** } Joomla 1.6 compability*/
            $list = @$children[$pt] ? $children[$pt] : array();
            array_push($list, $v);
            $children[$pt] = $list;
        }
        $cats = mosTreeRecurse(0, '', array(), $children, max(0, $levellimit - 1));
        $i = 0;
        $tmp_cats = array();
        foreach ($cats as $data) {
            $tmp_cats[$i] = $data;
            $i++;
        }
        $cats = array();
        $cats = $tmp_cats;
        //NEW
        $tmp = array();
        $last_catid = 0;
        foreach ($my_courses as $data) {
            if ($last_catid == 0 || $last_catid != $data->cat_id) {
                $last_catid = $data->cat_id;
            }
            $tmp[$last_catid][] = $data->id;
        }
        $for_not_empty = $tmp;
        //NEW
        $flms_course = array();
        if ($JLMS_CONFIG->get('flms_integration', 0)) {
            $query = "SELECT * FROM #__lmsf_courses";
            $JLMS_DB->setQuery($query);
            $flms_course = $JLMS_DB->loadObjectList();
        }
        $result_tree = array();
        $i = 0;
        while ($i < count($my_courses)) {
            $my_courses[$i]->c_id = $my_courses[$i]->id;
            $my_courses[$i]->id = -$my_courses[$i]->id;
            $i++;
        }
        foreach ($my_courses as $course) {
            $result_tree = new stdClass();
            $result_tree->c_id = $course->c_id;
            $result_tree->id = $course->id;
            $result_tree->parent = 0;
            $result_tree->name = $course->course_name;
            $result_tree->children = 0;
            $result_tree->is_course = 1;
            $result_tree->certificate = $course->certificate;
            $result_tree->ordering = $course->ordering;
            $position = 0;
            $i = 0;
            $level = 0;
            foreach ($cats as $cat) {
                if ($course->cat_id == $cat->id && $cat->parent == 0) {
                    $position = $i;
                    $result_tree->parent = $cat->id;
                }
                //				if ($cat->parent && isset($tmp_courses_cats[$course->c_id]) && count($tmp_courses_cats[$course->c_id]) && in_array($cat->id, $tmp_courses_cats[$course->c_id])) {
                if ($cat->parent && isset($for_not_empty[$cat->id]) && count($for_not_empty[$cat->id]) && in_array($course->c_id, $for_not_empty[$cat->id])) {
                    $position = $i;
                    $result_tree->parent = $cat->id;
                }
                $i++;
            }
            if ($position) {
                $new_cats = array();
                foreach ($cats as $cat) {
                    $new_cats[] = $cat;
                    if (count($new_cats) == $position + 1) {
                        //+1
                        $new_cats[] = $result_tree;
                    }
                }
                $cats = $new_cats;
            } else {
                $cats[] = $result_tree;
            }
        }
        $i = 0;
        while ($i < count($cats)) {
            $j = $i + 1;
            if ($cats[$i]->is_course) {
                while ($j < count($cats)) {
                    if (!$cats[$j]->is_course && $cats[$i]->parent == $cats[$j]->parent) {
                        $temp = new stdClass();
                        $temp = $cats[$j];
                        $cats[$j] = $cats[$i];
                        $cats[$i] = $temp;
                        break;
                    }
                    $j++;
                }
            }
            $i++;
        }
        $i = 0;
        while ($i < count($cats)) {
            $j = $i + 1;
            if ($cats[$i]->is_course) {
                while ($j < count($cats)) {
                    if ($cats[$j]->is_course && $cats[$i]->parent == $cats[$j]->parent) {
                        if ($JLMS_CONFIG->get('lms_courses_sortby', 0)) {
                            if ($cats[$j]->ordering < $cats[$i]->ordering) {
                                $temp = new stdClass();
                                $temp = $cats[$j];
                                $cats[$j] = $cats[$i];
                                $cats[$i] = $temp;
                            }
                        } else {
                            if (strcasecmp($cats[$j]->name, $cats[$i]->name) < 0) {
                                $temp = new stdClass();
                                $temp = $cats[$j];
                                $cats[$j] = $cats[$i];
                                $cats[$i] = $temp;
                            }
                        }
                    }
                    $j++;
                }
            }
            $i++;
        }
        $children = array();
        foreach ($cats as $v) {
            $pt = $v->parent;
            /** Joomla 1.6 compability { */
            $v->parent_id = $v->parent;
            $v->title = $v->name;
            /** } Joomla 1.6 compability*/
            $list = @$children[$pt] ? $children[$pt] : array();
            array_push($list, $v);
            $children[$pt] = $list;
        }
        $cats = mosTreeRecurse(0, '', array(), $children, max(0, $levellimit - 1));
        $tmp_cats_tmp = array();
        $i = 0;
        foreach ($cats as $cat) {
            $tmp_cats_tmp[$i] = $cat;
            $i++;
        }
        $cats = $tmp_cats_tmp;
        foreach ($cats as $key => $data) {
            $cats[$key]->exist_courses = 0;
            if ($data->is_course) {
                $catid = $data->parent;
                $i = $key;
                while ($i >= 0) {
                    if ($cats[$i]->id == $catid) {
                        $cats[$i]->exist_courses = 1;
                        $catid = $cats[$i]->parent;
                    }
                    $i--;
                }
            }
        }
        $tmp_cats = array();
        $i = 0;
        $lists['keep_flesson'] = 0;
        $tmp_data = array();
        foreach ($cats as $key => $data) {
            $tmp_data[$key] = $data;
            unset($tmp_data[$key]->treename);
            $tmp_data[$key]->folder_flag = 0;
            if ($data->children) {
                $tmp_data[$key]->folder_flag = 1;
            }
            $tmp_data[$key]->parent_id = $data->parent;
            $tmp_data[$key]->doc_name = $data->name;
            $tmp_data[$key]->ordering = $i;
            foreach ($flms_course as $f_course) {
                if ($data->is_course && abs($data->id) == $f_course->course_id && $f_course->type_lesson == 2) {
                    if ($f_course->like_theory) {
                        $f_course->pf_time = 0;
                        $f_course->pm_time = $f_course->theory_duration_time;
                    }
                    $pf_time_h = str_pad(floor($f_course->pf_time / 60), 2, "0", STR_PAD_LEFT);
                    $pf_time_m = str_pad($f_course->pf_time - $pf_time_h * 60, 2, "0", STR_PAD_LEFT);
                    $pf_time = $pf_time_h . ':' . $pf_time_m;
                    $pm_time_h = str_pad(floor($f_course->pm_time / 60), 2, "0", STR_PAD_LEFT);
                    $pm_time_m = str_pad($f_course->pm_time - $pm_time_h * 60, 2, "0", STR_PAD_LEFT);
                    $pm_time = $pm_time_h . ':' . $pm_time_m;
                    $pre_total_time = $f_course->pf_time + $f_course->pm_time;
                    $total_time_h = str_pad(floor($pre_total_time / 60), 2, "0", STR_PAD_LEFT);
                    $total_time_m = str_pad($pre_total_time - $total_time_h * 60, 2, "0", STR_PAD_LEFT);
                    $total_time = $total_time_h . ':' . $total_time_m;
                    $tmp_data[$key]->lesson_type = $f_course->type_lesson;
                    $tmp_data[$key]->pf_time = $pf_time;
                    $tmp_data[$key]->pm_time = $pm_time;
                    $tmp_data[$key]->total_time = $total_time;
                    $lists['keep_flesson'] = 1;
                } else {
                    if ($data->is_course && abs($data->id) == $f_course->course_id) {
                        $tmp_data[$key]->lesson_type = $f_course->type_lesson;
                    }
                }
            }
            if ($JLMS_CONFIG->get('multicat_no_display_empty', 1)) {
                //				if($data->is_course == 0 && $data->children && isset($tmp_cats_courses[$data->id]) && count($tmp_cats_courses[$data->id]) ){
                //				if($data->is_course == 0 && $data->children && $data->exist_courses ){
                if ($data->is_course == 0 && $data->children && $data->exist_courses) {
                    $tmp_cats[$i] = $tmp_data[$key];
                    $i++;
                } else {
                    if ($data->is_course && $data->children == 0) {
                        $tmp_cats[$i] = $tmp_data[$key];
                        $i++;
                    }
                }
            } else {
                $tmp_cats[$i] = $tmp_data[$key];
                $i++;
            }
        }
        $cats = $tmp_cats;
        $cats = JLMS_GetTreeStructure($cats);
        $my_courses = $cats;
        $hp_items = $JLMS_CONFIG->get('homepage_items');
    }
    //notices teacher
    if ($JLMS_CONFIG->get('frontpage_notices_teacher')) {
        $lists['my_notices'] = array();
        $hp_items = $JLMS_CONFIG->get('homepage_items');
        $query = "SELECT * " . "\n FROM #__lms_page_notices" . "\n WHERE usr_id = '" . $my->id . "'" . "\n ORDER BY data DESC" . "\n LIMIT 0,{$hp_items}";
        $JLMS_DB->setQuery($query);
        $lists['my_notices'] = $JLMS_DB->loadObjectList();
    }
    //dropbox
    $my_dropbox = array();
    if ($JLMS_CONFIG->get('frontpage_dropbox')) {
        $my_dropbox = my_dropboxes($c_str, $hp_items, $my->id);
    }
    $lists['dropbox_total'] = my_dropboxes_total($c_str, $my->id);
    $lists['dropbox_total_new'] = my_dropboxes_total_new($c_str, $my->id);
    //homework
    $my_hw = array();
    if ($JLMS_CONFIG->get('frontpage_homework')) {
        $my_hw = my_homeworks($c_str, $hp_items, $my->id);
        //		$members = "'0'";
        //		$where = '';
        //		if($JLMS_ACL->_role_type == 2 || $JLMS_ACL->_role_type == 3 || $JLMS_ACL->_role_type == 4) {
        //			if($assigned_groups_only) {
        //				$groups_where_admin_manager = JLMS_ACL_HELPER::GetAssignedGroups($my->id);
        //				$groups_where_isset_user = JLMS_ACL_HELPER::GetUserGlobalGroup($my->id);
        //
        //				$groups_where_admin_manager = array_merge($groups_where_admin_manager,$groups_where_isset_user);
        //
        //				if (count($groups_where_admin_manager)) {
        //					$where .= "\n AND ( `groups` LIKE '%|$groups_where_admin_manager[0]|%'";
        //					for($i=1;$i<count($groups_where_admin_manager);$i++) {
        //						$where .= "\n OR `groups` like '%|$groups_where_admin_manager[$i]|%'";
        //					}
        //					$where .=  "\n )";
        //				}
        //			}
        //		}
        //		elseif($JLMS_ACL->_role_type < 2) {
        //				$query = "select a.group_id FROM #__lms_users_in_global_groups as a WHERE a.user_id = '".$my->id."' AND a.subgroup1_id = 0";
        //				$JLMS_DB->setQuery($query);
        //				$temp1 = $JLMS_DB->loadResultArray();
        //
        //				$query = "select subgroup1_id FROM #__lms_users_in_global_groups WHERE user_id = '".$my->id."'";
        //				$JLMS_DB->setQuery($query);
        //				$temp2 = $JLMS_DB->loadResultArray();
        //
        //				$group_where_isset_user = array_merge($temp1,$temp2);
        //
        //				if (count($group_where_isset_user)) {
        //					$where .= "\n AND (( `groups` <> '' AND `groups` IS NOT NULL AND (`groups` LIKE '%|$group_where_isset_user[0]|%'";
        //					for($i=1;$i<count($group_where_isset_user);$i++) {
        //						$where .= "\n OR `groups` like '%|$group_where_isset_user[$i]|%'";
        //					}
        //					$where .=  "\n )) OR (`groups` = '' OR `groups` IS NULL))";
        //				}
        //		}
        //
        //
        //		$query = "SELECT a.*, b.course_name, d.hw_status, c.user_id as stu_id, e.user_id as teach_id"
        //		. "\n FROM (#__lms_homework as a, #__lms_courses as b)"
        //		. "\n LEFT JOIN #__lms_users_in_groups as c ON c.user_id = '".$my->id."' AND c.course_id = b.id"
        //		. "\n LEFT JOIN #__lms_homework_results as d ON d.course_id = b.id AND d.user_id = c.user_id AND d.hw_id = a.id"
        //		. "\n LEFT JOIN #__lms_user_courses as e ON e.course_id = b.id AND e.user_id = '".$my->id."'"
        //		. "\n WHERE a.course_id IN ($c_str) AND a.course_id = b.id AND a.end_date >= '".date('Y-m-d',time())."'"
        //		.$where
        //		. "\n LIMIT 0, $hp_items"
        //		;
        //		$JLMS_DB->SetQuery( $query );
        //		$my_hw = $JLMS_DB->LoadObjectList();
    }
    //announcements
    $my_announcements = array();
    if ($JLMS_CONFIG->get('frontpage_announcements')) {
        $my_announcements = my_announcements($c_str, $hp_items, $my->id);
    }
    //mailbox
    $my_mailbox = array();
    if ($JLMS_CONFIG->get('frontpage_mailbox')) {
        $my_mailbox = my_mailbox($c_str, $hp_items, $my->id);
    }
    //certificates
    $my_certificates = array();
    if ($JLMS_CONFIG->get('frontpage_certificates')) {
        $my_certificates = my_certificates($c_str, $hp_items, $my->id);
    }
    //latest forum posts
    $latest_forum_posts = array();
    if ($JLMS_CONFIG->get('frontpage_latest_forum_posts')) {
        $latest_forum_posts = latest_forum_posts($c_str, $hp_items, $my->id);
    }
    $lists['homepage_text'] = $JLMS_CONFIG->get('frontpage_text');
    //end
    JLMS_ShowHeading($JLMS_CONFIG->get('jlms_heading'), false);
    joomla_lms_html::showMainPage_front($option, $lists, $my_courses, $my_dropbox, $my_hw, $my_announcements, $my_mailbox, $my_certificates, $latest_forum_posts);
}
Example #8
0
function JLMS_deleteElement($topic_id, $course_id, $t_id)
{
    global $JLMS_DB, $Itemid, $option, $JLMS_CONFIG;
    $usertype = $JLMS_CONFIG->get('current_usertype', 0);
    if ($course_id == $JLMS_CONFIG->get('course_id') && $usertype == 1) {
        $cid = mosGetParam($_REQUEST, 'cid', array(0));
        $query = "DELETE FROM #__lms_topic_items WHERE id IN (" . implode(',', $cid) . ")";
        $JLMS_DB->setQuery($query);
        $JLMS_DB->query();
        fixElementOrder($topic_id);
        $msg = _JLMS_TOPIC_I_DELETED;
    }
    JLMSRedirect(sefRelToAbs("index.php?option={$option}&Itemid={$Itemid}&task=details_course&id={$course_id}" . ($t_id ? "&t_id=" . $t_id : "") . "#topic_{$topic_id}"), $msg);
}
 function JQ_ImgListcancel($option, $page, $id)
 {
     global $Itemid;
     JLMSRedirect(sefRelToAbs("index.php?option={$option}&Itemid={$Itemid}&task=quizzes&id={$id}&page=imgs"));
 }
Example #10
0
function show_agenda_items($id, $option, $rows, $date, $sort)
{
    global $Itemid;
    $selected = strval(mosGetParam($_REQUEST, 'jlms_agenda_order', ''));
    $selected_filter = strval(mosGetParam($_REQUEST, 'jlms_agenda_filter', ''));
    $JLMS_ACL =& JLMSFactory::getACL();
    if ($JLMS_ACL->CheckPermissions('announce', 'view')) {
        $lists = array();
        $order = array();
        //formiruem spisok Ordering
        $order[] = mosHTML::makeOption('desc', _JLMS_AGENDA_DESC);
        $order[] = mosHTML::makeOption('asc', _JLMS_AGENDA_ASC);
        $lists['order'] = mosHTML::selectList($order, 'jlms_agenda_order', 'class="inputbox" size="1" ', 'value', 'text', $selected);
        //formiruem spisok Filter
        $filter[] = mosHTML::makeOption('0', _JLMS_SB_FILTER_NONE);
        $filter[] = mosHTML::makeOption('current', _JLMS_AGENDA_TODAY);
        $filter[] = mosHTML::makeOption('upcoming', _JLMS_AGENDA_UPCOMING);
        $lists['filter'] = mosHTML::selectList($filter, 'jlms_agenda_filter', 'class="inputbox" size="1" ', 'value', 'text', $selected_filter);
        function add_to_agenda(&$agenda, $d)
        {
            $do_add = true;
            for ($i = 0, $n = count($agenda); $i < $n; $i++) {
                if ($agenda[$i]->a_y . '-' . $agenda[$i]->a_m == substr($d, 0, 7)) {
                    $do_add = false;
                }
            }
            if ($do_add) {
                $ff = new stdClass();
                $ff->a_y = substr($d, 0, 4);
                $ff->a_m = substr($d, 5, 2);
                $ff->items = array();
                $agenda[] = $ff;
            }
        }
        function fill_my(&$agenda, &$st, &$en)
        {
            $i = 0;
            $do = true;
            while ($do) {
                $d = date("Y-m-1", strtotime("+{$i} month", strtotime($st)));
                if (strtotime($d) <= strtotime($en)) {
                    add_to_agenda($agenda, $d);
                } else {
                    $do = false;
                }
                $i++;
            }
        }
        $agenda = array();
        foreach ($rows as $row) {
            $tmp_date = $row->start_date;
            fill_my($agenda, $row->start_date, $row->end_date);
        }
        for ($i = 0, $n = count($agenda) - 1; $i < $n; $i++) {
            for ($j = $i, $m = count($agenda); $j < $m; $j++) {
                if ($sort == 'asc') {
                    if ($agenda[$j]->a_y < $agenda[$i]->a_y || $agenda[$j]->a_y == $agenda[$i]->a_y && $agenda[$j]->a_m < $agenda[$i]->a_m) {
                        $k = $agenda[$j];
                        $agenda[$j] = $agenda[$i];
                        $agenda[$i] = $k;
                    }
                } else {
                    if ($agenda[$j]->a_y > $agenda[$i]->a_y || $agenda[$j]->a_y == $agenda[$i]->a_y && $agenda[$j]->a_m > $agenda[$i]->a_m) {
                        $k = $agenda[$j];
                        $agenda[$j] = $agenda[$i];
                        $agenda[$i] = $k;
                    }
                }
            }
        }
        //		print_r($agenda);die;
        foreach ($rows as $row) {
            for ($i = 0, $n = count($agenda); $i < $n; $i++) {
                if ($agenda[$i]->a_y . '-' . $agenda[$i]->a_m == substr($row->start_date, 0, 7) || $agenda[$i]->a_y . '-' . $agenda[$i]->a_m == substr($row->end_date, 0, 7) || strtotime($agenda[$i]->a_y . '-' . $agenda[$i]->a_m . '-1') >= strtotime($row->start_date) && strtotime($agenda[$i]->a_y . '-' . $agenda[$i]->a_m . '-1') <= strtotime($row->end_date)) {
                    $agenda[$i]->items[] = $row;
                }
            }
        }
        JLMS_agenda_html::show_agenda_items($id, $option, $rows, $date, $lists, $agenda);
    } else {
        JLMSRedirect(sefRelToAbs("index.php?option={$option}&amp;Itemid={$Itemid}"));
    }
}
Example #11
0
function JLMS_showChat($course_id, $option)
{
    global $JLMS_DB, $my, $Itemid, $JLMS_CONFIG;
    $JLMS_ACL =& JLMSFactory::getACL();
    if ($JLMS_ACL->CheckPermissions('chat', 'view')) {
        global $JLMS_CONFIG;
        $pathway = array();
        $pathway[] = array('name' => _JLMS_PATHWAY_HOME, 'link' => sefRelToAbs("index.php?option={$option}&amp;Itemid={$Itemid}"), 'is_home' => true);
        $pathway[] = array('name' => $JLMS_CONFIG->get('course_name'), 'link' => sefRelToAbs("index.php?option={$option}&amp;Itemid={$Itemid}&amp;task=details_course&amp;id={$course_id}"), 'is_course' => true);
        $pathway[] = array('name' => _JLMS_TOOLBAR_CHAT, 'link' => sefRelToAbs("index.php?option={$option}&amp;Itemid={$Itemid}&amp;task=chat&amp;id={$course_id}"));
        JLMSAppendPathWay($pathway);
        JLMS_ShowHeading();
        $group_id = intval(mosGetParam($_REQUEST, 'group_id', 0));
        if ($JLMS_ACL->CheckPermissions('chat', 'manage')) {
            if ($JLMS_CONFIG->get('use_global_groups', 1)) {
                $query = "SELECT group_chat FROM #__lms_usergroups WHERE course_id = 0 AND id = {$group_id}";
                $JLMS_DB->SetQuery($query);
                $gr_c = $JLMS_DB->LoadResult();
                if (!$gr_c) {
                    $group_id = 0;
                }
            } else {
                $query = "SELECT group_chat FROM #__lms_usergroups WHERE course_id = {$course_id} AND id = {$group_id}";
                $JLMS_DB->SetQuery($query);
                $gr_c = $JLMS_DB->LoadResult();
                if (!$gr_c) {
                    $group_id = 0;
                }
            }
        } else {
            if ($JLMS_CONFIG->get('use_global_groups', 1)) {
                if ($group_id) {
                    $query = "SELECT group_chat FROM #__lms_users_in_global_groups AS uigg, #__lms_usergroups AS ug WHERE uigg.user_id = {$my->id} AND uigg.group_id = {$group_id} AND ug.id = uigg.group_id";
                    $JLMS_DB->setQuery($query);
                    if (!$JLMS_DB->loadResult()) {
                        $group_id = 0;
                    }
                }
            } else {
                if ($group_id) {
                    $query = "SELECT a.group_id FROM #__lms_users_in_groups as a, #__lms_usergroups as b WHERE a.course_id = {$course_id} AND a.user_id = '" . $my->id . "' AND a.group_id = b.id AND b.course_id = {$course_id} AND b.group_chat = 1";
                    $JLMS_DB->SetQuery($query);
                    $group_id = $JLMS_DB->LoadResult();
                    if (!$group_id) {
                        $group_id = 0;
                    }
                }
            }
        }
        $query = "SHOW COLUMNS FROM `#__lms_chat_history` WHERE Field = 'user_message'";
        $JLMS_DB->SetQuery($query);
        $chat_table = $JLMS_DB->LoadObject();
        if (is_object($chat_table) && isset($chat_table->Type)) {
            if ($chat_table->Type != 'text') {
                $query = "ALTER TABLE `#__lms_chat_history` CHANGE `user_message` `user_message` TEXT";
                $JLMS_DB->SetQuery($query);
                $JLMS_DB->query();
            }
        }
        //query (Drop users)
        $query = "DELETE FROM #__lms_chat_users WHERE user_id = '" . $my->id . "'";
        $JLMS_DB->SetQuery($query);
        $JLMS_DB->query();
        $tim_minus_15 = time() - date('Z') - 15 * 60;
        $query = "DELETE FROM #__lms_chat_users WHERE time_post < '" . date('Y-m-d H:i:s', $tim_minus_15) . "'";
        $JLMS_DB->SetQuery($query);
        $JLMS_DB->query();
        //query (Entering chat)
        $query = "INSERT INTO #__lms_chat_users (course_id, group_id, user_id, time_enter, time_post, chat_option)" . "\n VALUES ('" . $course_id . "', '" . $group_id . "', '" . $my->id . "', '" . gmdate('Y-m-d H:i:s') . "', '" . gmdate('Y-m-d H:i:s') . "', '0')";
        $JLMS_DB->SetQuery($query);
        $JLMS_DB->query();
        //tracking
        global $Track_Object;
        $Track_Object->UserEnterChat($my->id, $course_id);
        $query = "SELECT a.username FROM #__users as a, #__lms_chat_users as b" . "\n WHERE a.id = b.user_id AND b.course_id = '" . $course_id . "' AND b.group_id = '" . $group_id . "'" . "\n ORDER BY a.username";
        $JLMS_DB->SetQuery($query);
        $chat_users = $JLMS_DB->LoadObjectList();
        $course_chats = array();
        $course_chats[] = mosHTML::makeOption(0, _JLMS_CHAT_COURSE_CHAT);
        if ($JLMS_ACL->CheckPermissions('chat', 'manage')) {
            if ($JLMS_CONFIG->get('use_global_groups', 1)) {
                $query = "SELECT ug.id AS value, ug.ug_name AS text" . "\n FROM #__lms_usergroups AS ug, #__lms_users_in_groups AS uig, #__lms_users_in_global_groups AS uigg" . "\n WHERE ug.group_chat = 1 AND uig.course_id = {$course_id} AND uigg.user_id = uig.user_id AND ug.id = uigg.group_id";
                $JLMS_DB->setQuery($query);
                $group_chats = $JLMS_DB->loadObjectList();
                for ($i = 0; $i < count($group_chats); $i++) {
                    $group_chats[$i]->text = $group_chats[$i]->text . " (" . _JLMS_CHAT_GROUP_CHAT . ")";
                }
                $course_chats = array_merge($course_chats, $group_chats);
            } else {
                $query = "SELECT id as value, ug_name as text FROM #__lms_usergroups WHERE course_id = {$course_id} AND group_chat = 1";
                $JLMS_DB->SetQuery($query);
                $group_chats = $JLMS_DB->loadObjectList();
                for ($i = 0; $i < count($group_chats); $i++) {
                    $group_chats[$i]->text = $group_chats[$i]->text . " (" . _JLMS_CHAT_GROUP_CHAT . ")";
                }
                $course_chats = array_merge($course_chats, $group_chats);
            }
        } else {
            if ($JLMS_CONFIG->get('use_global_groups', 1)) {
                $query = "SELECT ug.id AS value, ug.ug_name AS text" . "\n FROM #__lms_usergroups AS ug, #__lms_users_in_groups AS uig, #__lms_users_in_global_groups AS uigg" . "\n WHERE uig.course_id = {$course_id} AND uigg.user_id = uig.user_id AND ug.id = uigg.group_id AND ug.group_chat = 1 AND uig.user_id = {$my->id}";
                $JLMS_DB->setQuery($query);
                $group_chats = $JLMS_DB->loadObjectList();
                for ($i = 0; $i < count($group_chats); $i++) {
                    $group_chats[$i]->text = $group_chats[$i]->text . " (" . _JLMS_CHAT_GROUP_CHAT . ")";
                }
                $course_chats = array_merge($course_chats, $group_chats);
            } else {
                $query = "SELECT b.id as value, b.ug_name as text FROM #__lms_users_in_groups as a, #__lms_usergroups as b WHERE a.course_id = {$course_id} AND a.user_id = '" . $my->id . "' AND a.group_id = b.id AND b.course_id = {$course_id} AND b.group_chat = 1";
                $JLMS_DB->SetQuery($query);
                $group_chats = $JLMS_DB->loadObjectList();
                for ($i = 0; $i < count($group_chats); $i++) {
                    $group_chats[$i]->text = _JLMS_CHAT_GROUP_CHAT . " (" . $group_chats[$i]->text . ")";
                }
                $course_chats = array_merge($course_chats, $group_chats);
            }
        }
        /*if (JLMS_GetUserType_simple($my->id) == 1) {
        		$query = "SELECT distinct b.* FROM #__lms_courses as b, #__lms_user_courses as a"
        		. "\n WHERE a.course_id = b.id AND a.user_id = '".$my->id."'";
        		} elseif (JLMS_GetUserType_simple($my->id) == 2) {
        		$query = "SELECT distinct a.* FROM #__lms_courses as a, #__lms_usergroups as b, #__lms_users_in_groups as c"
        		. "\n WHERE a.id = b.course_id AND b.id = c.group_id AND c.user_id = '".$my->id."'";
        		}
        		$JLMS_DB->SetQuery( $query );
        		$rows = $JLMS_DB->LoadObjectList();*/
        $lists = array();
        $javascript = 'onchange="document.chatForm.submit();"';
        $lists['course_chats'] = mosHTML::selectList($course_chats, 'group_id', 'class="inputbox" size="1" ' . $javascript, 'value', 'text', $group_id);
        JLMS_chat_html::showChat($course_id, $group_id, $option, $lists, $chat_users);
    } else {
        JLMSRedirect(sefRelToAbs("index.php?option={$option}&Itemid={$Itemid}"));
    }
}
Example #12
0
    function show_checkout($option, $subscription, $item_id, $proc)
    {
        global $Itemid, $JLMS_CONFIG, $JLMS_DB;
        $task2 = strval(mosGetParam($_REQUEST, 'task2', ''));
        if ($task2 == 'show_info') {
            // do nothing... proceed to the code below
        } else {
            JLMSRedirect(sefRelToAbs("index.php?option=" . $option . "&amp;Itemid=" . $Itemid . "&amp;task=checkout_cart&amp;task2=show_info&amp;order_id={$item_id}&amp;proc={$proc->id}&amp;proc_id={$proc->id}"));
            exit;
        }
        $params = new JLMSParameters($proc->params);
        $html = $params->get('page_info', 'Your OrderID: {ORDER_ID}, Total amount: {TOTAL}. Invoice: {invoice}.');
        // do not use language files for this setting, this is default value from processor XML
        $rowz = new jlms_adm_config();
        $rowz->loadFromDb($JLMS_DB);
        $replace_it = '{invoice}';
        $replace_to = 'link';
        $inv_close_pos = strpos($html, '{/invoice}');
        if ($inv_close_pos === false) {
        } else {
            $inv_open_pos = strpos($html, '{invoice}');
            if ($inv_open_pos === false) {
            } elseif ($inv_open_pos < $inv_close_pos) {
                $replace_it = substr($html, $inv_open_pos, $inv_close_pos - $inv_open_pos + 10);
                $replace_to = substr($html, $inv_open_pos + 9, $inv_close_pos - $inv_open_pos - 9);
            }
        }
        if ($params->get('subscr_status') == 1 && $rowz->jlms_subscr_status_email) {
            $query = "SELECT lms_config_value FROM #__lms_config  WHERE lms_config_var = 'jlms_subscr_invoice_path'";
            $JLMS_DB->setQuery($query);
            $file_path = $JLMS_DB->loadResult();
            $query = "SELECT filename FROM #__lms_subs_invoice WHERE subid = " . (int) $item_id;
            $JLMS_DB->setQuery($query);
            if ($JLMS_DB->loadResult()) {
                $filename = $file_path . '/' . $JLMS_DB->loadResult();
            } else {
                $filename = '';
            }
            if ($filename && is_file($filename)) {
                $filename = '<a href="' . JRoute::_('index.php?option=com_joomla_lms&Itemid=' . $Itemid . '&task=get_payment_invoice&id=' . $item_id) . '" target="_blank">' . $replace_to . '</a>';
                $html = str_replace($replace_it, $filename, $html);
            } else {
                $html = str_replace($replace_it, '-', $html);
            }
        } else {
            $html = str_replace($replace_it, '-', $html);
        }
        $html = str_replace('{ORDER_ID}', $item_id, $html);
        $total = number_format($subscription->price + $subscription->tax_amount, 2, '.', '') . '' . $JLMS_CONFIG->get('jlms_cur_code');
        $html = str_replace('{TOTAL}', $total, $html);
        ?>
			<?php 
        echo $subscription->sub_name ? JLMSCSS::h2($subscription->sub_name) : '';
        echo $html;
        ?>
<br /><br />
			<a href='<?php 
        echo sefRelToAbs("index.php?option=com_joomla_lms&Itemid={$Itemid}&task=courses");
        ?>
'><?php 
        echo _JLMS_HOME_COURSES_LIST_HREF;
        ?>
</a>
		<?php 
    }
Example #13
0
 function validate_callback($proc)
 {
     global $Itemid, $JLMS_CONFIG, $JLMS_DB;
     $params = new JLMSParameters($proc->params);
     $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);
     //mosMail( '*****@*****.**', 'BOT LMS Trial', '*****@*****.**', 'Paypal', $server_url2, false, NULL, NULL );
     // assign posted variables to local variables
     $item_name = $_POST['item_name'];
     $item_number = $_POST['item_number'];
     $payment_status = $_POST['payment_status'];
     $payment_amount = $_POST['mc_gross'];
     $payment_currency = $_POST['mc_currency'];
     $txn_id = $_POST['txn_id'];
     $receiver_email = $_POST['receiver_email'];
     $business = $_POST['business'];
     $payer_email = $_POST['payer_email'];
     $payment_date = $_POST['payment_date'];
     $tax_amount = $_POST['option_selection1'];
     $tax_paypal = isset($_POST['tax']) ? $_POST['tax'] : 0;
     if (!$fp) {
         // nothing here ?!
     } else {
         fputs($fp, $header . $req);
         while (!feof($fp)) {
             $res_pp = fgets($fp, 1024);
             if (strcmp($res_pp, "VERIFIED") == 0) {
                 /// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!  VERIFIED  !!!!!!!!!!!!!!!!!11
                 require_once _JOOMLMS_FRONT_HOME . '/includes/joomla_lms.subscription.lib.php';
                 if ($payment_status == 'Completed') {
                     // check that receiver_email is your Primary PayPal email
                     if ($receiver_email != $params->get('business_email') && $business != $params->get('business_email')) {
                         die;
                     }
                     if ($payment_currency != $JLMS_CONFIG->get('jlms_cur_code')) {
                         die;
                     }
                     if (!jlms_check_payment_transaction($payment_amount - $tax_paypal, $item_number)) {
                         die('Invalid payment amount');
                     }
                     $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 + $tax_paypal, $tax_paypal);
                     if ($prev_payment == 'Completed') {
                     } else {
                         jlms_register_new_user($item_number);
                     }
                 } elseif ($payment_status == 'Pending') {
                     jlms_update_payment($item_number, $txn_id, 'Pending', $payment_date, $tax_amount, $tax_paypal);
                 }
             } elseif (strcmp($res_pp, "INVALID") == 0) {
                 JLMSRedirect(sefRelToAbs("index.php?option=com_joomla_lms&Itemid={$Itemid}"));
             }
         }
         fclose($fp);
     }
 }
Example #14
0
 function validate_callback($proc)
 {
     global $Itemid, $JLMS_CONFIG, $JLMS_DB;
     $params = new JLMSParameters($proc->params);
     if (!isset($_REQUEST["x_invoice_num"]) || empty($_REQUEST["x_invoice_num"])) {
         echo "Order ID is not set or empty!";
     } else {
         if ($_REQUEST['x_Login'] != $params->get('x_login', '')) {
             die('Invalid account number.');
         }
         // demo transaction
         if (isset($_REQUEST['demo']) && $_REQUEST['demo'] == "Y" && !$params->get('demo', '')) {
             die('Demo mode is switched off.');
         }
         $order_number = mosGetParam($_REQUEST, "x_invoice_num");
         $compare_string = $params->get('x_secret') . $params->get('x_login') . $_REQUEST['order_number'] . $_REQUEST['x_amount'];
         $payment_date = date("Y-m-d H:i:s", mktime());
         $compare_hash1 = strtoupper(md5($compare_string));
         $compare_hash2 = $_REQUEST['x_MD5_Hash'];
         if ($compare_hash1 != $compare_hash2 && !$params->get('demo')) {
             die('Invalid secret hash.');
         }
         if ($_REQUEST['x_response_code'] == '1' && $_REQUEST['x_2checked'] == 'Y') {
             $payment_amount = $_REQUEST['x_amount'];
             $tax_amount = $_REQUEST['tax_amount'];
             $txn_id = $_REQUEST['x_trans_id'];
             if ($params->get('demo')) {
                 $txn_id .= ' - demo mode';
             }
             $payment_date = date("Y-m-d H:i:s");
             $order_id = $_REQUEST['custom'];
             $user_id = $_REQUEST['userid'];
             $payment_currency = $JLMS_CONFIG->get('jlms_cur_code');
             require_once _JOOMLMS_FRONT_HOME . '/includes/joomla_lms.subscription.lib.php';
             if (!jlms_check_payment_transaction($payment_amount - $tax_amount, $order_id)) {
                 die('Invalid payment amount');
             }
             $query = "SELECT status FROM `#__lms_payments` WHERE id = {$order_id} ";
             $JLMS_DB->setQuery($query);
             $prev_payment = $JLMS_DB->LoadResult();
             jlms_update_payment($order_id, $txn_id, 'Completed', $payment_date);
             if ($prev_payment == 'Completed') {
             } else {
                 jlms_register_new_user($order_id);
             }
         }
         if ($params->get('return_url') == '') {
             JLMSRedirect($JLMS_CONFIG->get('live_site'));
         } else {
             JLMSRedirect($params->get('return_url'));
         }
     }
 }
Example #15
0
function JLMS_playerSCORM($id, $option)
{
    global $JLMS_DB, $my, $JLMS_CONFIG, $Itemid, $JLMS_SESSION;
    $course_id = $JLMS_CONFIG->get('course_id');
    $usertype = $JLMS_CONFIG->get('current_usertype', 0);
    $lpath_id = intval(mosGetParam($_REQUEST, 'lpath_id', 0));
    $int_skip_resume = intval(mosGetParam($_REQUEST, 'int_skip_resume', 0));
    $scorm = null;
    //new stdClass();
    if ($course_id && ($usertype == 1 || $usertype == 2) && JLMS_CheckSCORM($id, $lpath_id, $course_id, $scorm, $usertype)) {
        if (!empty($scorm)) {
            // 11.04.2007 (parameter 'redirect_to_learnpath' used to avoid redirect cycles from course home to LP and back
            $JLMS_SESSION->clear('redirect_to_learnpath');
            // sleep one second. SCORM could send some requests on onCloasPage event. We need wait for these requests to be processed.
            #sleep(2);
            $scoid = intval(mosGetParam($_REQUEST, 'scoid', 0));
            $mode = 'normal';
            //strval(mosGetParam($_REQUEST, 'mode','normal'));//optional_param('mode', 'normal', PARAM_ALPHA);
            $currentorg = strval(mosGetParam($_REQUEST, 'currentorg', ''));
            //, PARAM_RAW);
            $newattempt = strval(mosGetParam($_REQUEST, 'newattempt', 'on'));
            require_once _JOOMLMS_FRONT_HOME . "/includes/n_scorm/lms_scorm.play.php";
            $query = "SELECT * FROM #__lms_learn_paths WHERE id = '" . $lpath_id . "' AND course_id = '" . $course_id . "'";
            $JLMS_DB->SetQuery($query);
            $lpath_data = $JLMS_DB->LoadObjectList();
            $box_view = false;
            if (count($lpath_data) == 1) {
                $pathway = array();
                $pathway[] = array('name' => $lpath_data[0]->lpath_name, 'link' => sefRelToAbs("index.php?option={$option}&amp;Itemid={$Itemid}&amp;task=player_scorm&amp;id={$id}&amp;course_id={$course_id}&amp;lpath_id=" . $lpath_data[0]->id));
                JLMSAppendPathWay($pathway);
            }
            if (isset($scorm->params)) {
                $params = new JLMSParameters($scorm->params);
                if ($params->get('scorm_layout', 0) && $params->get('scorm_layout', 0) == 1) {
                    $box_view = true;
                }
            }
            if ($box_view) {
                // SqueezeBox view - don't show Heading.
                echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">';
                echo '<html xmlns="http://www.w3.org/1999/xhtml" style="margin:0;padding:0"><head>';
                $iso_site = 'charset=utf-8';
                if (defined('_ISO')) {
                    $iso_site = _ISO;
                    if (!$iso_site) {
                        $iso_site = 'charset=utf-8';
                    }
                }
                echo '<meta http-equiv="Content-Type" content="text/html; ' . $iso_site . '" />';
                echo '</head><body style="margin:0;padding:0">';
            } else {
                JLMS_ShowHeading();
            }
            /*JLMS_TMPL::OpenMT();
            
            			$hparams = array();
            			JLMS_TMPL::ShowHeader('scorm', $scorm->scorm_name, $hparams);
            */
            $skip_resume = $int_skip_resume ? true : false;
            JLMS_SCORM_PLAY_MAIN($scorm, $option, $course_id, $lpath_id, $scoid, $mode, $currentorg, $newattempt, false, false, $box_view, $skip_resume);
            if ($box_view) {
                echo '</body></html>';
                JLMS_die();
            }
            //JLMS_TMPL::CloseMT();
        } else {
            JLMSRedirect(sefRelToAbs("index.php?option={$option}&Itemid={$Itemid}&task=learnpaths&id={$course_id}"));
        }
    } else {
        JLMSRedirect(sefRelToAbs("index.php?option={$option}&Itemid={$Itemid}&task=learnpaths&id={$course_id}"));
    }
}
function JLMS_show_course_forum($id, $option)
{
    /*
    board_type = 1 - Public/Group course board
    board_type = 2 - LearningPath public course board
    board_type = 3 - Board for users from 'Global group'
    board_type = 4 - Private (teachers-only) boards
    board_type = 5 - Private (teachers-only) LearningPath boards
    */
    global $my, $JLMS_DB, $Itemid, $JLMS_CONFIG;
    $doc =& JFactory::getDocument();
    $usertype = JLMS_GetUserType($my->id, $id);
    if (!$usertype) {
        JLMSRedirect(sefRelToAbs("index.php?option={$option}&Itemid={$Itemid}&task=details_course&id={$id}"));
    }
    $JLMS_ACL =& JLMSFactory::getACL();
    $forum =& JLMS_SMF::getInstance();
    if (!$forum) {
        return false;
    }
    $id_cat = 0;
    $course_name = '';
    $owner_name = '';
    $private_forums_tobe_created = array();
    // list of private forums to be created
    $msg = '';
    //error message - prompt to login if not blank
    $query = "SELECT * FROM #__lms_forums WHERE published = 1";
    $JLMS_DB->setQuery($query);
    $lms_forum_types = $JLMS_DB->loadObjectList('id');
    //[TODO] - check all types of the forums and create/remove necessary forum boards in the SMF - i.e. if they wasn't be created/removed previously
    // Note, autocreation is necessary only for 'global groups' forums and private forums (`access` is 1)
    $give_course_forums = array();
    $need_to_create = false;
    $need_to_update = false;
    if (count($lms_forum_types)) {
        // check all forum types for access.
        $allowed_forum_types = array();
        // allowed forum types
        $lms_forum_types_ids = array();
        foreach ($lms_forum_types as $lft) {
            $do_proceeed = true;
            // firstly - check `access` and `permissions`
            switch (intval($lft->forum_access)) {
                case 0:
                    // any user
                    break;
                case 1:
                    // check user role
                    if ($lft->forum_permissions) {
                        $allowed_roles = explode(',', $lft->forum_permissions);
                        if ($JLMS_ACL->GetRole() && in_array($JLMS_ACL->GetRole(), $allowed_roles)) {
                            // allow access
                        } else {
                            // restrict access if this forum is not permissioned.
                            $do_proceeed = false;
                        }
                    } else {
                        // if this is a restricted area but there is no roles configured
                        $do_proceeed = false;
                    }
                    break;
            }
            if (!$do_proceeed) {
                continue;
            }
            // secondly - check `user_level` permissions
            switch (intval($lft->user_level)) {
                case 0:
                    // any user
                    break;
                case 1:
                    // local usergroup forum
                // local usergroup forum
                case 2:
                    // global usergroup forum
                    if ($lft->user_level == 1 && $JLMS_CONFIG->get('use_global_groups', 1)) {
                        $do_proceeed = false;
                        // restrict access to the local-group forum, if we are in the global mode
                    } elseif ($lft->user_level == 2 && !$JLMS_CONFIG->get('use_global_groups', 1)) {
                        $do_proceeed = false;
                        // restrict access to the global-group forum, if we are in the local mode
                    }
                    break;
            }
            if (!$do_proceeed) {
                continue;
            }
            $allowed_forum_types[$lft->id] = $lft;
            // we have a list of allowed forum types here.
            $lms_forum_types_ids[] = $lft->id;
        }
        if (count($lms_forum_types_ids)) {
            $query = "SELECT id, course_id, board_type, group_id, ID_GROUP AS id_group, ID_CAT AS id_cat, ID_BOARD AS id_board, is_active, need_update FROM #__lms_forum_details" . "\n WHERE course_id = {$id}" . "\n AND board_type IN (" . implode(',', $lms_forum_types_ids) . ")";
            $JLMS_DB->setQuery($query);
            $active_course_forums = $JLMS_DB->loadObjectList();
            for ($i = 0; $i < count($active_course_forums); $i++) {
                $active_course_forums[$i]->forum_level = $lms_forum_types[$active_course_forums[$i]->board_type]->forum_level;
                $active_course_forums[$i]->user_level = $lms_forum_types[$active_course_forums[$i]->board_type]->user_level;
                $active_course_forums[$i]->forum_access = $lms_forum_types[$active_course_forums[$i]->board_type]->forum_access;
                $active_course_forums[$i]->forum_permissions = $lms_forum_types[$active_course_forums[$i]->board_type]->forum_permissions;
                $active_course_forums[$i]->parent_forum = $lms_forum_types[$active_course_forums[$i]->board_type]->parent_forum;
                $active_course_forums[$i]->forum_moderators = $lms_forum_types[$active_course_forums[$i]->board_type]->forum_moderators;
                $active_course_forums[$i]->forum_name = $lms_forum_types[$active_course_forums[$i]->board_type]->forum_name;
                $active_course_forums[$i]->forum_desc = $lms_forum_types[$active_course_forums[$i]->board_type]->forum_desc;
                $active_course_forums[$i]->moderated = $lms_forum_types[$active_course_forums[$i]->board_type]->moderated;
                // !!!! ATTENTION, `need_update` field was moved to the `lms_forum_details` table //$active_course_forums[$i]->need_update = $lms_forum_types[$active_course_forums[$i]->board_type]->need_update;
            }
            // [TODO] - inspect each forum type and populate list of necessary forums (to be created or already created)
            $give_course_forums = array();
            foreach ($allowed_forum_types as $aft) {
                switch (intval($aft->forum_level)) {
                    case 0:
                        switch (intval($aft->user_level)) {
                            case 0:
                                //one forum should be created for course.
                                $forum->populateCourseForums($id, $give_course_forums, $active_course_forums, $aft);
                                break;
                            case 1:
                                $forum->populateLgroupForums($id, $give_course_forums, $active_course_forums, $aft);
                                break;
                            case 2:
                                $forum->populateGgroupForums($id, $give_course_forums, $active_course_forums, $aft);
                                break;
                        }
                        break;
                    case 1:
                        if (intval($aft->user_level) == 0) {
                            $forum->populateLpathForums($id, $give_course_forums, $active_course_forums, $aft);
                        } else {
                            //ignore any other forums - currently there is no posibility to have such difficult structure
                        }
                        break;
                }
            }
            if (count($give_course_forums)) {
                $need_to_create = false;
                for ($i = 0; $i < count($give_course_forums); $i++) {
                    if ($give_course_forums[$i]->id == 0) {
                        $need_to_create = true;
                    }
                    if (isset($give_course_forums[$i]->need_update) && $give_course_forums[$i]->need_update) {
                        $need_to_update = true;
                    }
                    if ($need_to_create && $need_to_update) {
                        break;
                    }
                }
            }
        }
    }
    $was_created = array();
    $was_updated = array();
    $newcat_wascreated = false;
    if (count($give_course_forums)) {
        //echo '<pre>';var_dump($give_course_forums);die;
        if ($need_to_create || $need_to_update) {
            $query = "SELECT a.course_name, a.owner_id, b.username as owner_name FROM #__lms_courses as a LEFT JOIN #__users as b ON a.owner_id = b.id WHERE a.id = {$id}";
            $JLMS_DB->setQuery($query);
            $course_info = $JLMS_DB->loadObject();
            if (is_object($course_info)) {
                $course_name = $course_info->course_name;
                // - we need it to create boards
                $owner_name = $course_info->owner_name;
            }
        }
        $query = "SELECT ID_CAT AS id_cat FROM #__lms_forum_details WHERE course_id = {$id} LIMIT 0,1";
        $JLMS_DB->setQuery($query);
        $id_cat = $JLMS_DB->loadResult();
        // ID of the Course CATEGORY (in which all course boards are placed) - we need it to create boards
        // TODO:
        // check if SMF boards was removed and create new ones if necessary!
        $query = "SELECT distinct ID_GROUP AS id_group FROM `#__lms_forum_details` ";
        $JLMS_DB->setQuery($query);
        $all_lms_groups = $JLMS_DB->loadResultArray();
        $all_moderator_ids = array();
        $all_moderators = array();
        for ($i = 0; $i < count($give_course_forums); $i++) {
            if (($need_to_create && $give_course_forums[$i]->id == 0 || $give_course_forums[$i]->need_update) && $give_course_forums[$i]->forum_moderators) {
                $new_moderators = explode(',', $give_course_forums[$i]->forum_moderators);
                $all_moderator_ids = array_merge($all_moderator_ids, $new_moderators);
            }
        }
        if (count($all_moderator_ids)) {
            for ($i = 0; $i < count($all_moderator_ids); $i++) {
                $all_moderator_ids[$i] = intval($all_moderator_ids[$i]);
            }
            $all_moderator_ids = array_unique($all_moderator_ids);
            if (!empty($all_moderator_ids)) {
                $all_moderator_ids_str = implode(',', $all_moderator_ids);
                $query = "SELECT id, username FROM #__users WHERE id IN ({$all_moderator_ids_str})";
                $JLMS_DB->setQuery($query);
                $all_moderators = $JLMS_DB->LoadObjectList('id');
            }
        }
        if (!$id_cat) {
            // CATEGORY for this course doesn't exists - we need to create new one
            $storeData = array();
            $storeData['name'] = $course_name;
            $storeData['can_collapse'] = 1;
            $id_cat = $forum->storeCategory($storeData);
            $newcat_wascreated = true;
            // TODO:
            // if instead CAT_ID #__forum_details was populated with 0 - we need to update #__forum_details table and boards in SMF db
            // all updates to Joola db are 100 - 150 lines below
        }
        $user_exists = false;
        $is_forum_category = 0;
        $boardurl = $forum->getBoardURL();
        $link = $boardurl . '/index.php#' . $id_cat;
        $smf_user_details = $forum->loadMemberByName($my->username);
        if ($smf_user_details) {
            $user_exists = true;
            $all_current_smf_groups = array();
            // create all parent forums
            for ($i = 0; $i < count($give_course_forums); $i++) {
                if ($need_to_create && $give_course_forums[$i]->id == 0 && !$give_course_forums[$i]->parent_forum) {
                    if ($give_course_forums[$i]->forum_level == 1 && $give_course_forums[$i]->user_level == 0 || $give_course_forums[$i]->forum_level == 0 && $give_course_forums[$i]->user_level == 2 || $give_course_forums[$i]->forum_level == 0 && $give_course_forums[$i]->user_level == 0) {
                        $tmp = $forum->create($give_course_forums, $i, $course_name, $owner_name, $all_moderators, $id_cat);
                        $was_created[] = $tmp;
                        $all_current_smf_groups[] = $tmp->id_group;
                    }
                } elseif ($give_course_forums[$i]->id && $give_course_forums[$i]->need_update && !$give_course_forums[$i]->parent_forum) {
                    $tmp = $forum->update($give_course_forums, $i, $course_name, $owner_name, $all_moderators, $id_cat);
                    $was_updated[] = $tmp;
                    $all_current_smf_groups[] = $give_course_forums[$i]->id_group;
                } elseif ($give_course_forums[$i]->id && !$give_course_forums[$i]->need_update) {
                    $all_current_smf_groups[] = $give_course_forums[$i]->id_group;
                }
            }
            //crate all nested forums
            for ($i = 0; $i < count($give_course_forums); $i++) {
                if ($need_to_create && $give_course_forums[$i]->id == 0 && $give_course_forums[$i]->parent_forum) {
                    if ($give_course_forums[$i]->forum_level == 1 && $give_course_forums[$i]->user_level == 0 || $give_course_forums[$i]->forum_level == 0 && $give_course_forums[$i]->user_level == 2 || $give_course_forums[$i]->forum_level == 0 && $give_course_forums[$i]->user_level == 0) {
                        $tmp = $forum->create($give_course_forums, $i, $course_name, $owner_name, $all_moderators, $id_cat);
                        $was_created[] = $tmp;
                        $all_current_smf_groups[] = $tmp->id_group;
                    }
                } elseif ($give_course_forums[$i]->id && $give_course_forums[$i]->need_update && $give_course_forums[$i]->parent_forum) {
                    $tmp = $forum->update($give_course_forums, $i, $course_name, $owner_name, $all_moderators, $id_cat);
                    $was_updated[] = $tmp;
                    $all_current_smf_groups[] = $give_course_forums[$i]->id_group;
                }
            }
            $mem_id = $smf_user_details->id_member;
            $mem_real_name = $smf_user_details->real_name;
            $primary_group = $smf_user_details->id_group;
            $old_groups = explode(',', $smf_user_details->additional_groups);
            $old_groups_save = array();
            foreach ($old_groups as $group) {
                if (!in_array($group, $all_lms_groups)) {
                    $old_groups_save[] = $group;
                }
            }
            $forum_groups = array_unique(array_merge($all_current_smf_groups, $old_groups_save));
            $new_forum_groups = array();
            foreach ($forum_groups as $fg) {
                if ($fg) {
                    $new_forum_groups[] = $fg;
                }
            }
            $groups = implode(',', $new_forum_groups);
            if (!$mem_real_name && isset($my->name) && $my->name) {
                // update real_name of user, if it is missed
                $storeData = array();
                $storeData['id_member'] = $mem_id;
                $storeData['id_group'] = $primary_group;
                $storeData['additional_groups'] = $groups;
                $storeData['real_name'] = $my->name;
            } else {
                $storeData = array();
                $storeData['id_member'] = $mem_id;
                $storeData['id_group'] = $primary_group;
                $storeData['additional_groups'] = $groups;
            }
            $forum->storeMember($storeData);
            if (count($give_course_forums) == 1) {
                $is_forum_category = 0;
                $link = $boardurl . '/index.php?board=' . $give_course_forums[0]->id_board . '.0';
            } elseif (count($give_course_forums) > 1) {
                $is_forum_category = 1;
                $link = $boardurl . '/index.php#' . $id_cat;
            }
            $topic_id = JRequest::getVar('topic_id', 0);
            $message_id = JRequest::getVar('message_id', 0);
            if ($topic_id && $message_id) {
                $link = $boardurl . '/index.php';
                $link .= '?topic=' . $topic_id;
                $link .= '.msg' . $message_id;
                $link .= '#msg' . $message_id;
            }
            if (true) {
                //($is_forum_category) {
                $forum_tree = $forum->selectBoards();
                $user_cats = array();
                foreach ($forum_tree as $ft) {
                    $ar = $ft->member_groups;
                    $ar = explode(',', $ar);
                    $is_cat = false;
                    foreach ($new_forum_groups as $gia) {
                        if (in_array($gia, $ar)) {
                            $is_cat = true;
                            break;
                        }
                    }
                    if ($is_cat) {
                        $user_cats[] = $ft->id_cat;
                    }
                }
                $user_cats = array_unique($user_cats);
                if (count($user_cats)) {
                    $forum->deleteCollapsedCategories($mem_id, $user_cats);
                    $new_ar = array($id_cat);
                    $rrr = array_diff($user_cats, $new_ar);
                    $forum->insertCollapsedCategories($mem_id, $rrr);
                }
            }
        }
        $mem_id_cookies = 0;
        if ($user_exists) {
            $mem_id_cookies = JLMS_checkSMF_cookies(false);
        }
        if ($need_to_create) {
            if (count($was_created)) {
                $query = "INSERT INTO #__lms_forum_details (course_id, board_type, group_id, ID_GROUP, ID_CAT, ID_BOARD, is_active) VALUES";
                $first = 1;
                foreach ($was_created as $obj) {
                    $query .= $first ? '' : ',';
                    $query .= "\n({$id}, {$obj->board_type}, {$obj->group_id}, {$obj->id_group}, {$obj->id_cat}, {$obj->id_board}, 1)";
                    $first = 0;
                }
                $JLMS_DB->setQuery($query);
                $JLMS_DB->query();
            }
        }
        if (isset($was_updated) && count($was_updated)) {
            $was_updated = array_unique($was_updated);
            if (!empty($was_updated)) {
                $was_updated_str = implode(',', $was_updated);
                $query = "UPDATE #__lms_forum_details SET need_update = 0 WHERE id IN ({$was_updated_str}) AND need_update = 1";
                $JLMS_DB->setQuery($query);
                $JLMS_DB->query();
            }
        }
        if ($user_exists) {
            if ($mem_id && $mem_id_cookies && $mem_id_cookies == $mem_id) {
                $mbname = $forum->getMbname();
                $doc->setTitle($mbname);
                //[TODO] - what is it - $mbname and $boardurl - from the Settings.php?
            } else {
                $msg = JLMS_FORUM_NOT_MEMBER;
            }
        } else {
            $msg = JLMS_FORUM_NOT_MEMBER;
        }
    } else {
        JLMSRedirect(sefRelToAbs("index.php?option={$option}&Itemid={$Itemid}&task=details_course&id={$id}"));
    }
    JLMS_course_forum_html::wrapper_course_forum($link, $option, $id, $msg);
    return true;
}
function jlms_booking_users_delete($cid, $course_id, $option)
{
    global $JLMS_DB;
    if (count($cid)) {
        $pid = intval(mosgetparam($_POST, "p_id", 0));
        $cids = implode(',', $cid);
        $query = "DELETE FROM #__lms_conference_usr WHERE p_id = '" . $pid . "' AND user_id IN (" . $cids . ")";
        $JLMS_DB->setQuery($query);
        if (!$JLMS_DB->query()) {
            echo "<script> alert('" . $JLMS_DB->getErrorMsg() . "'); window.history.go(-1); </script>\n";
            exit;
        }
    }
    JLMSRedirect(sefRelToAbs('index.php?option=' . $option . '&amp;task=conference&amp;mode=user_access&amp;id=' . $course_id . '&amp;pid=' . $pid));
}
function JLMS_tchangeHW($course_id, $option)
{
    $JLMS_CONFIG =& JLMSFactory::getConfig();
    $Itemid = $JLMS_CONFIG->get('Itemid');
    $_JLMS_PLUGINS =& JLMSFactory::getPlugins();
    $db =& JFactory::getDbo();
    $user_id = intval(mosGetParam($_REQUEST, 'user_id', 0));
    $JLMS_ACL =& JLMSFactory::getACL();
    if ($course_id && $user_id && $JLMS_ACL->CheckPermissions('homework', 'manage')) {
        $state = intval(mosGetParam($_REQUEST, 'state', 0));
        if ($state != 1) {
            $state = 0;
        }
        //$state = 1;
        $cid = mosGetParam($_REQUEST, 'cid', array(0));
        $cid2 = intval(mosGetParam($_REQUEST, 'cid2', 0));
        if ($cid2) {
            $cid = array();
            $cid[] = $cid2;
        }
        if (!is_array($cid)) {
            $cid = array(0);
        }
        if (!is_array($cid) || count($cid) < 1) {
            $action = 1 ? 'Publish' : 'Unpublish';
            echo "<script> alert('Select an item to {$action}'); window.history.go(-1);</script>\n";
            exit;
        }
        $cid1 = array();
        $cid1[] = $cid[0];
        $cids = implode(',', $cid1);
        //$now = date( 'Y-m-d', time() );
        //check rights to change id's
        $query = "SELECT id FROM #__lms_homework WHERE course_id = '" . $course_id . "'" . "\n AND id IN ( {$cids} )";
        $db->SetQuery($query);
        $cid = $db->LoadResultArray();
        if (!is_array($cid)) {
            $cid = array(0);
        }
        $cids = implode(',', $cid);
        $query = "SELECT hw_id FROM #__lms_homework_results WHERE course_id = '" . $course_id . "' AND user_id = '" . $user_id . "' AND hw_id IN ( {$cids} )";
        $db->SetQuery($query);
        $pre_cids = $db->LoadResultArray();
        if (!count($pre_cids)) {
            $pre_cids = array(0);
        }
        $upd_cid = array_intersect($cid, $pre_cids);
        $ins_cid = array_diff($cid, $pre_cids);
        $now = date('Y-m-d H:i:s');
        if (!$state) {
            $now = '';
        }
        $hw_id_notify = 0;
        if (count($upd_cid)) {
            $cids = implode(',', $upd_cid);
            if (isset($upd_cid[0]) && $upd_cid[0]) {
                $hw_id_notify = $upd_cid[0];
            }
            $query = "UPDATE #__lms_homework_results" . "\n SET hw_status = {$state}, hw_date = '" . $now . "'" . "\n WHERE hw_id IN ( {$cids} ) AND course_id = {$course_id} AND user_id = '" . $user_id . "'";
            $db->setQuery($query);
            if (!$db->query()) {
                echo "<script> alert('" . $db->getErrorMsg() . "'); window.history.go(-1); </script>\n";
                exit;
            }
        }
        if (count($ins_cid)) {
            if (isset($ins_cid[0]) && $ins_cid[0]) {
                $hw_id_notify = $ins_cid[0];
            }
            $query = "INSERT INTO #__lms_homework_results (course_id, user_id, hw_id, hw_status, hw_date) VALUES ";
            $t = 0;
            foreach ($ins_cid as $ins_id) {
                $query .= "\n ({$course_id}, " . $user_id . ", " . $ins_id . ", {$state}, '" . $now . "')" . ($t < count($ins_cid) - 1 ? ',' : '');
                $t++;
            }
            $db->setQuery($query);
            if (!$db->query()) {
                echo "<script> alert('" . $db->getErrorMsg() . "'); window.history.go(-1); </script>\n";
                exit;
            }
        }
        if ($state && $hw_id_notify) {
            //*** email notification about new homework submission
            $e_course = new stdClass();
            $e_course->course_alias = '';
            $e_course->course_name = '';
            $query = "SELECT course_name, name_alias FROM #__lms_courses WHERE id = '" . $course_id . "'";
            $db->setQuery($query);
            $e_course = $db->loadObject();
            $query = "SELECT hw_name FROM #__lms_homework WHERE id = '" . $hw_id_notify . "'";
            $db->setQuery($query);
            $e_hw_name = $db->loadResult();
            $e_user = new stdClass();
            $e_user->name = '';
            $e_user->email = '';
            $e_user->username = '';
            $query = "SELECT email, name, username FROM #__users WHERE id = '" . $user_id . "'";
            $db->setQuery($query);
            $e_user = $db->loadObject();
            $e_params['user_id'] = $user_id;
            $e_params['course_id'] = $course_id;
            $e_params['markers']['{email}'] = $e_user->email;
            $e_params['markers']['{name}'] = $e_user->name;
            $e_params['markers']['{username}'] = $e_user->username;
            $e_params['markers']['{coursename}'] = $e_course->course_name;
            //( $e_course->course_alias )?$e_course->course_alias:$e_course->course_name;
            $e_params['markers']['{homeworkname}'] = $e_hw_name;
            $e_params['markers']['{courselink}'] = JLMSEmailRoute("index.php?option=com_joomla_lms&Itemid={$Itemid}&task=details_course&id={$course_id}");
            $e_params['markers_nohtml']['{courselink}'] = $e_params['markers']['{courselink}'];
            $e_params['markers']['{courselink}'] = '<a href="' . $e_params['markers']['{courselink}'] . '">' . $e_params['markers']['{courselink}'] . '</a>';
            $e_params['markers']['{lmslink}'] = 'OnCSVImportUser';
            $e_params['markers']['{lmslink}'] = JLMSEmailRoute("index.php?option=com_joomla_lms&Itemid={$Itemid}");
            $e_params['markers_nohtml']['{lmslink}'] = $e_params['markers']['{lmslink}'];
            $e_params['markers']['{lmslink}'] = '<a href="' . $e_params['markers']['{lmslink}'] . '">' . $e_params['markers']['{lmslink}'] . '</a>';
            $e_params['action_name'] = 'OnHomeworkReview';
            $_JLMS_PLUGINS->loadBotGroup('emails');
            $plugin_result_array = $_JLMS_PLUGINS->trigger('OnHomeworkReview', array(&$e_params));
            //*** end of emails
        }
    }
    JLMSRedirect(sefRelToAbs("index.php?option={$option}&Itemid={$Itemid}&task=hw_stats&course_id={$course_id}&id={$cid[0]}"));
}