function bot_docmanpaypalprices2($params)
{
    global $mainframe, $_DOCMAN, $_DMUSER, $currency_symbols;
    $database =& JFactory::getDBO();
    $my = JFactory::getUser();
    require_once $_DOCMAN->getPath('classes', 'button');
    require_once $_DOCMAN->getPath('classes', 'token');
    $_DOCMAN->loadLanguage('frontend');
    $doc =& $params['doc'];
    $file =& $params['file'];
    $objDBDoc = $doc->objDBTable;
    $buttonStaysBuyNow = false;
    $objFormatData = $doc->objFormatData;
    if ($objFormatData->id > 0) {
        $currency = docmanpaypal::cfg('currency');
        $gid = $objFormatData->id;
        $item = docmanpaypal::getItem($gid);
        $database->setQuery("select price from #__docmanpaypal where id = '{$gid}' limit 1;");
        $price = $database->loadResult();
        $database->setQuery("select dmdescription from #__docman where id = {$gid} limit 1");
        $dmdescription = $database->loadResult();
        $document_price = number_format($price, 2);
        //free fownloads for user in specific groups
        if ($my->id > 0) {
            $tmp = docmanpaypal::cfg('free_for_usertypes');
            $tmp = explode(',', $tmp);
            if (in_array($my->usertype, $tmp)) {
                $price = 0;
            }
            if (docmanpaypal::isInDOCmanFreeDownloadGroup()) {
                $price = 0;
            }
            //die($price);
        }
        //free fownloads for user in specific groups END
        if ($price > 0) {
            $document_price = number_format($price, 2);
            $priceFormat = docmanpaypal::cfg('priceFormat');
            $priceFormatted = str_replace(array('%priceText%', '%price%', '%currency%'), array(_DMP_PRICE, $document_price, $currency), $priceFormat);
            $objFormatData->dmdescription = $priceFormatted . $dmdescription;
            $objFormatData->dmdescription = str_replace('%price%', $currency_symbols[$currency] . number_format($price, 2), $objFormatData->dmdescription);
            //$objFormatData->dmdescription = '<div id="DMP_PRICE_DIV"><span class="DMP_PRICE">' . _DMP_PRICE . '</span> <span class="DMP_PRICE_VALUE">' . $document_price . '</span> <span class="DMP_PRICE_CURRENCY">' . $currency . '</span></div>' . $dmdescription;
        }
    }
    $botParams = bot_docmanpaypalpricesParams2();
    //print_r($botParams);
    $js = "javascript:if(confirm('" . _DML_ARE_YOU_SURE . "')) {window.location='%s'}";
    $buttons = array();
    $tmp = docmanpaypal::cfg('moreThanOnce');
    if ($tmp > 0 && $my->id > 0) {
        unset($tmp);
        $database->setQuery("select order_id from #__docmanpaypalorders where buyer_id = " . $my->id . " and file_id = {$gid} OR file_id like '{$gid},%' or file_id like '%,{$gid},%' or file_id like '%,{$gid}' and completed = 1 order by order_id desc limit 1");
        //die($database->getQuery());
        $tmp = $database->loadResult();
        if ($tmp > 0) {
            $database->setQuery("select downloads from #__docmanpaypaldownloads where order_id = {$tmp} and id = {$gid} order by order_id desc limit 1");
            //die($database->getQuery());
            $downloads = $database->loadResult();
            if ($downloads < $item->downloadslimit && is_null($downloads) == false) {
                $price = 0;
            }
            $buttonStaysBuyNow = docmanpaypal::cfg('buttonStaysBuyNow');
        }
    }
    //offline good update
    if ($item->offlineGood > 0) {
        $price = $item->price;
    }
    //
    if ($botParams->get('priceInBuyNow', 1)) {
        $priceInBuyNow = ' (' . $currency_symbols[$currency] . number_format($price, 2) . ')';
    }
    if ($botParams->get('priceInTitle', 1) && $price > 0) {
        $objFormatData->dmname .= ' - ' . $currency_symbols[$currency] . number_format($price, 2);
    }
    if ($price > 0) {
        if ($_DMUSER->canDownload($objDBDoc) and $botParams->get('download', 1)) {
            if (docmanpaypal::cfg('useCart') > 0) {
                $buttons['addToCart'] = new DOCMAN_Button('addToCart', _DMP_ADD_TO_CART, 'javascript:addToCart(' . $gid . ');');
            }
            if ($botParams->get('buynow', 1)) {
                $buttons['download'] = new DOCMAN_Button('download', _DMP_BUY_NOW . $priceInBuyNow, $doc->_formatLink('doc_download'));
            }
        }
    } else {
        //die('shit');
        if ($_DMUSER->canDownload($objDBDoc) and $botParams->get('download', 1) and $buttonStaysBuyNow == 0) {
            $buttons['download'] = new DOCMAN_Button('download', _DML_BUTTON_DOWNLOAD, $doc->_formatLink('doc_download'));
        }
        if ($_DMUSER->canDownload($objDBDoc) and $botParams->get('download', 1) and $buttonStaysBuyNow == 1) {
            $buttons['download'] = new DOCMAN_Button('download', _DMP_BUY_NOW . $priceInBuyNow, $doc->_formatLink('doc_download'));
        }
    }
    //pdfPreview option
    if (pathinfo($objFormatData->dmfilename, PATHINFO_EXTENSION) == 'pdf' && docmanpaypal::cfg('pdfPreviewPages') > 0 && $price > 0) {
        $buttons['pdfPreview'] = new DOCMAN_Button('pdfPreview', _DMP_PDFPREVIEWBUTTON, JRoute::_('index.php?&option=com_docmanpaypal&task=pdfPreview&id=' . $gid));
    }
    //
    //custom buttons
    if ($item->buttons != '' && strpos($item->buttons, '|')) {
        $tmp = str_replace("\r", "", $item->buttons);
        $tmp = explode("\n", $tmp);
        foreach ($tmp as $tmp) {
            if (strpos($tmp, "|")) {
                $t = explode("|", $tmp);
                $btn++;
                if (count($t) > 1) {
                    $buttons['btn' . $btn] = new DOCMAN_Button('btn' . $btn, $t[0], JRoute::_($t[1]));
                }
            }
        }
    }
    //
    if ($_DMUSER->canDownload($objDBDoc) and $botParams->get('view', 1) && $price == 0) {
        $viewtypes = trim($_DOCMAN->getCfg('viewtypes'));
        if ($viewtypes != '' && ($viewtypes == '*' || stristr($viewtypes, $file->ext))) {
            $link = $doc->_formatLink('doc_view', null, true, 'index2.php');
            $params = new DMmosParameters('popup=1');
            $buttons['view'] = new DOCMAN_Button('view', _DML_BUTTON_VIEW, $link, $params);
        }
    }
    if ($botParams->get('details', 1)) {
        $buttons['details'] = new DOCMAN_Button('details', _DML_BUTTON_DETAILS, $doc->_formatLink('doc_details'));
    }
    if ($_DMUSER->canEdit($objDBDoc) and $botParams->get('edit', 1)) {
        $buttons['edit'] = new DOCMAN_Button('edit', _DML_BUTTON_EDIT, $doc->_formatLink('doc_edit'));
    }
    if ($_DMUSER->canMove($objDBDoc) and $botParams->get('move', 1)) {
        $buttons['move'] = new DOCMAN_Button('move', _DML_BUTTON_MOVE, $doc->_formatLink('doc_move'));
    }
    if ($_DMUSER->canDelete($objDBDoc) and $botParams->get('delete', 1)) {
        $link = $doc->_formatLink('doc_delete', null, null, null, true);
        $buttons['delete'] = new DOCMAN_Button('delete', _DML_BUTTON_DELETE, sprintf($js, $link));
    }
    if ($_DMUSER->canUpdate($objDBDoc) and $botParams->get('update', 1)) {
        $buttons['update'] = new DOCMAN_Button('update', _DML_BUTTON_UPDATE, $doc->_formatLink('doc_update'));
    }
    if ($_DMUSER->canReset($objDBDoc) and $botParams->get('reset', 1)) {
        $buttons['reset'] = new DOCMAN_Button('reset', _DML_BUTTON_RESET, sprintf($js, $doc->_formatLink('doc_reset')));
    }
    if ($_DMUSER->canCheckin($objDBDoc) and $objDBDoc->checked_out and $botParams->get('checkout', 1)) {
        $params = new DMmosParameters('class=checkin');
        $buttons['checkin'] = new DOCMAN_Button('checkin', _DML_BUTTON_CHECKIN, $doc->_formatLink('doc_checkin'), $params);
    }
    if ($_DMUSER->canCheckout($objDBDoc) and !$objDBDoc->checked_out and $botParams->get('checkout', 1)) {
        $buttons['checkout'] = new DOCMAN_Button('checkout', _DML_BUTTON_CHECKOUT, $doc->_formatLink('doc_checkout'));
    }
    if ($_DMUSER->canApprove($objDBDoc) and !$objDBDoc->approved and $botParams->get('approve', 1)) {
        $params = new DMmosParameters('class=approve');
        $link = $doc->_formatLink('doc_approve', null, null, null, true);
        $buttons['approve'] = new DOCMAN_Button('approve', _DML_BUTTON_APPROVE, $link, $params);
    }
    if ($_DMUSER->canPublish($objDBDoc) and $botParams->get('publish', 1)) {
        $params = new DMmosParameters('class=publish');
        $link = $doc->_formatLink('doc_publish', null, null, null, true);
        $buttons['publish'] = new DOCMAN_Button('publish', _DML_BUTTON_PUBLISH, $link, $params);
    }
    if ($_DMUSER->canUnPublish($objDBDoc) and $botParams->get('publish', 1)) {
        $link = $doc->_formatLink('doc_unpublish', null, null, null, true);
        $buttons['unpublish'] = new DOCMAN_Button('unpublish', _DML_BUTTON_UNPUBLISH, $link);
    }
    //print_r($buttons);
    return $buttons;
}
 function getItem($id)
 {
     $db = JFactory::getDBO();
     $db->setQuery("SELECT *\nFROM `#__docmanpaypal` d\nLEFT JOIN #__docmanpaypalvendors v ON d.vendor = v.vendor_id\nLEFT JOIN #__docman_documents dm ON d.id = dm.docman_document_id where dm.docman_document_id = {$id}\nLIMIT 1");
     $obj = $db->loadObject();
     $obj->dmname = $obj->title;
     $obj->id = $obj->docman_document_id;
     if ($obj->mypercent > 0) {
         $obj->paypalemail = docmanpaypal::cfg('paypalemail');
     }
     return $obj;
 }