private function renderItems($oContainerTpl, $results, $topic)
 {
     // main shop_content
     global $ilUser;
     $items_counter = 0;
     $cur_obj_type = '';
     $tpl = $this->newBlockTemplate();
     foreach ($this->type_ordering as $act_type) {
         $item_html = array();
         if (count($results[(int) $topic['id']][$act_type])) {
             foreach ($results[$topic['id']][$act_type] as $key => $item) {
                 // price presentation
                 $oPaymentObject = new ilPaymentObject($ilUser, ilPaymentObject::_lookupPobjectId($item['ref_id']));
                 $oPrice = new ilPaymentPrices((int) $oPaymentObject->getPobjectId());
                 $lowest_price = $oPrice->getLowestPrice();
                 $special_icon = ' ';
                 if ($oPaymentObject->getSpecial() == '1') {
                     $special_icon = ilShopUtils::_getSpecialObjectSymbol();
                 }
                 $results[$topic['id']][$act_type][$key]['title'] = $item['title'] . ' ' . ($results[$topic['id']][$act_type][$key]['special_icon'] = $special_icon);
                 $results[$topic['id']][$act_type][$key]['price'] = $lowest_price['price'];
                 $paymethod_icon = ilShopUtils::_getPaymethodSymbol($oPaymentObject->getPayMethod());
                 $shoppingcart_icon = ilShopUtils::_addToShoppingCartSymbol($item['ref_id']);
                 $results[$topic['id']][$act_type][$key]['price_string'] = ($oPrice->getNumberOfPrices() > 1 ? $this->lng->txt('price_from') . ' ' : '') . ilPaymentPrices::_formatPriceToString($lowest_price['price']) . ' ' . ($results[$topic['id']][$act_type][$key]['shoppingcart_icon'] = $shoppingcart_icon . ' ' . ($results[$topic['id']][$act_type][$key]['paymethod_icon'] = $paymethod_icon));
                 // authors
                 include_once 'Services/MetaData/classes/class.ilMD.php';
                 $md_obj = new ilMD($item['obj_id'], 0, $item['type']);
                 if (is_object($md_section = $md_obj->getLifecycle())) {
                     $sep = $ent_str = "";
                     foreach ($ids = $md_section->getContributeIds() as $con_id) {
                         $md_con = $md_section->getContribute($con_id);
                         if ($md_con->getRole() == "Author") {
                             foreach ($ent_ids = $md_con->getEntityIds() as $ent_id) {
                                 $md_ent = $md_con->getEntity($ent_id);
                                 $ent_str = $ent_str . $sep . $md_ent->getEntity();
                                 $sep = ", ";
                             }
                         }
                     }
                     $results[$topic['id']][$act_type][$key]['author'] = $ent_str;
                 }
             }
             $results[$topic['id']][$act_type] = $this->sortResult($results[$topic['id']][$act_type]);
             foreach ($results[$topic['id']][$act_type] as $key => $item) {
                 // get list gui class for each object type
                 list($item, $html) = $this->getObjectListItem($cur_obj_type, $item);
                 if ($html) {
                     $item_html[$item['ref_id']] = $html;
                 }
             }
             // output block for resource type
             if (count($item_html) > 0) {
                 // add a header for each resource type
                 $tpl->setCurrentBlock("container_header_row_image");
                 $tpl->setVariable("HEADER_IMG", ilObject::_getIcon('', '', $act_type));
                 $tpl->setVariable("HEADER_ALT", $this->lng->txt("objs_" . $act_type));
                 $tpl->setVariable("BLOCK_HEADER_CONTENT", $this->lng->txt("objs_" . $act_type));
                 $this->resetRowType();
                 // content row
                 foreach ($item_html as $ref_id => $html) {
                     $this->addStandardRow($tpl, $html);
                 }
                 ++$items_counter;
             }
         }
     }
     if ($items_counter > 0) {
         $oContainerTpl->setCurrentBlock('loop_item');
         $oContainerTpl->setCurrentBlock('topic_title');
         $oContainerTpl->setVariable('TOPIC_TITLE', $topic['title']);
         $oContainerTpl->parseCurrentBlock('topic_title');
         $oContainerTpl->setVariable('CONTAINER_LIST_BLOCK', $html);
         $oContainerTpl->parseCurrentBlock('loop_item');
         $tpl->setContent($oContainerTpl->get());
         $container_html = $tpl->get();
         return $container_html;
     }
 }
 private function renderItems($oContainerTpl, $results, $topic)
 {
     // main shop_content
     global $ilUser;
     $items_counter = 0;
     $cur_obj_type = '';
     $tpl = $this->newBlockTemplate();
     $first = true;
     foreach ($this->type_ordering as $act_type) {
         $item_html = array();
         if (count($results[$topic['id']][$act_type])) {
             foreach ($results[$topic['id']][$act_type] as $key => $item) {
                 // price presentation
                 $oPaymentObject = new ilPaymentObject($ilUser, ilPaymentObject::_lookupPobjectId($item['ref_id']));
                 $oPrice = new ilPaymentPrices((int) $oPaymentObject->getPobjectId());
                 $lowest_price = $oPrice->getLowestPrice();
                 $special_icon = ' ';
                 if ($oPaymentObject->getSpecial() == '1') {
                     $special_icon = ilShopUtils::_getSpecialObjectSymbol();
                 }
                 $results[$topic['id']][$act_type][$key]['title'] = $item['title'] . ' ' . ($results[$topic['id']][$act_type][$key]['special_icon'] = $special_icon);
                 $results[$topic['id']][$act_type][$key]['price'] = $lowest_price['price'];
                 $paymethod_icon = ilShopUtils::_getPaymethodSymbol($oPaymentObject->getPayMethod());
                 //					if(!ilPaymentObject::_hasAccess($item['ref_id']))
                 //					{
                 $shoppingcart_icon = ilShopUtils::_addToShoppingCartSymbol($act_type, $item['ref_id']);
                 //					}
                 //					else $shoppingcart_icon = '';
                 $results[$topic['id']][$act_type][$key]['price_string'] = ($oPrice->getNumberOfPrices() > 1 ? $this->lng->txt('price_from') . ' ' : '') . ilPaymentPrices::_formatPriceToString($lowest_price['price']) . ' ' . ($results[$topic['id']][$act_type][$key]['shoppingcart_icon'] = $shoppingcart_icon . ' ' . ($results[$topic['id']][$act_type][$key]['paymethod_icon'] = $paymethod_icon));
                 // authors
                 include_once 'Services/MetaData/classes/class.ilMD.php';
                 $md_obj = new ilMD($item['obj_id'], 0, $item['type']);
                 if (is_object($md_section = $md_obj->getLifecycle())) {
                     $sep = $ent_str = "";
                     foreach ($ids = $md_section->getContributeIds() as $con_id) {
                         $md_con = $md_section->getContribute($con_id);
                         if ($md_con->getRole() == "Author") {
                             foreach ($ent_ids = $md_con->getEntityIds() as $ent_id) {
                                 $md_ent = $md_con->getEntity($ent_id);
                                 $ent_str = $ent_str . $sep . $md_ent->getEntity();
                                 $sep = ", ";
                             }
                         }
                     }
                     $results[$topic['id']][$act_type][$key]['author'] = $ent_str;
                 }
             }
             $results[$topic['id']][$act_type] = $this->sortResult($results[$topic['id']][$act_type]);
             foreach ($results[$topic['id']][$act_type] as $key => $item) {
                 // get list gui class for each object type
                 if ($cur_obj_type != $item['type']) {
                     include_once 'Services/Object/classes/class.ilObjectListGUIFactory.php';
                     $item_list_gui = ilObjectListGUIFactory::_getListGUIByType($item['type']);
                 }
                 $item_list_gui->initItem($item['ref_id'], $item['obj_id'], $item['title'], $item['description'], ilObjectListGUI::CONTEXT_SHOP);
                 $item_list_gui->enableDelete(false);
                 $item_list_gui->enableCut(false);
                 $item_list_gui->enableCopy(false);
                 $item_list_gui->enableLink(false);
                 $item_list_gui->enableSubscribe(false);
                 $item_list_gui->enablePayment(true);
                 $item_list_gui->enableCommands(true);
                 $item_list_gui->enablePath(false);
                 $item_list_gui->insertCommands();
                 $item_list_gui->enableInfoScreen(false);
                 $item_list_gui->enableSubstitutions(false);
                 $item_list_gui->enableNoticeProperties(false);
                 $item_list_gui->enablePreconditions(false);
                 $item_list_gui->enableProperties(false);
                 $item_list_gui->setBoldTitle(true);
                 if (ilPaymentObject::_hasAccess($item['ref_id'])) {
                     $item_list_gui->enableInfoScreen(true);
                     $item_list_gui->enableCommands(true);
                 } else {
                     switch ($item['type']) {
                         case 'sahs':
                             $demo_link = 'ilias.php?baseClass=ilSAHSPresentationGUI&ref_id=' . $item['ref_id'] . '&purchasetype=demo';
                             break;
                         case 'lm':
                             $demo_link = 'ilias.php?baseClass=ilLMPresentationGUI&ref_id=' . $item['ref_id'] . '&purchasetype=demo';
                             break;
                         case 'exc':
                             $demo_link = $this->ctrl->getLinkTargetByClass('ilshoppurchasegui', 'showDemoVersion') . '&purchasetype=demo&ref_id=' . $item["ref_id"];
                             break;
                         default:
                             $demo_link = $this->ctrl->getLinkTargetByClass('ilshoppurchasegui', 'showDemoVersion') . '&purchasetype=demo&ref_id=' . $item["ref_id"];
                             break;
                     }
                     $item['title'] = '<a href="' . $demo_link . '">' . $item["title"] . '</a>';
                 }
                 $tpl_pinfo = new ilTemplate('tpl.shop_item_info.html', true, true, 'Services/Payment');
                 if ($item['price_string'] != '') {
                     $tpl_pinfo->setCurrentBlock('ploop');
                     $tpl_pinfo->setVariable('PROPERTY', $this->lng->txt('price_a'));
                     $tpl_pinfo->setVariable('VALUE', $item['price_string']);
                     $tpl_pinfo->parseCurrentBlock();
                 }
                 if ($item['author'] != '') {
                     $tpl_pinfo->setCurrentBlock('ploop');
                     $tpl_pinfo->setVariable('PROPERTY', $this->lng->txt('author'));
                     $tpl_pinfo->setVariable('VALUE', $item['author']);
                     $tpl_pinfo->parseCurrentBlock();
                 }
                 $oFile = new ilFileDataShop(ilPaymentObject::_lookupPobjectId($item['ref_id']));
                 if (($webpath_file = $oFile->getCurrentImageWebPath()) !== false) {
                     $tpl_pinfo->setCurrentBlock('image');
                     $tpl_pinfo->setVariable('SRC', $webpath_file);
                     $tpl_pinfo->setVariable('ALT', strip_tags($item['title']));
                     $tpl_pinfo->parseCurrentBlock();
                 }
                 $item_list_gui->addSubItemHTML($tpl_pinfo->get());
                 $html = $item_list_gui->getListItemHTML($item['ref_id'], $item['obj_id'], $item['title'], $item['description'], false, false, "", ilObjectListGUI::CONTEXT_SHOP);
                 if ($html) {
                     $html = $this->__appendChildLinks($html, $item, $item_list_gui);
                     $item_html[$item['ref_id']] = $html;
                 }
             }
             // output block for resource type
             if (count($item_html) > 0) {
                 // separator row
                 if (!$first) {
                     $this->addSeparatorRow($tpl);
                 }
                 $first = false;
                 // add a header for each resource type
                 $this->addHeaderRow($tpl, $act_type);
                 $this->resetRowType();
                 // content row
                 foreach ($item_html as $ref_id => $html) {
                     $this->addStandardRow($tpl, $html, $ref_id);
                 }
                 ++$items_counter;
             }
         }
     }
     if ($items_counter > 0) {
         $oContainerTpl->setCurrentBlock('loop');
         $oContainerTpl->setVariable('TOPIC_TITLE', $topic['title']);
         $oContainerTpl->setVariable('COTAINER_LIST_BLOCK', $tpl->get());
         $oContainerTpl->parseCurrentBlock();
         global $tpl;
         $tpl->setContent($oContainerTpl->get());
     }
 }
 private function addBookings($pay_method, $coupon_session)
 {
     global $ilUser, $ilObjDataCache;
     include_once './Services/Payment/classes/class.ilPaymentBookings.php';
     include_once './Services/Payment/classes/class.ilPaymentObject.php';
     include_once './Services/Payment/classes/class.ilPaymentPrices.php';
     $booking_obj = new ilPaymentBookings();
     $sc_obj = new ilPaymentShoppingCart($this->user_obj);
     $items = $sc_obj->getEntries($pay_method);
     $sc_obj->clearCouponItemsSession();
     foreach ($items as $entry) {
         $pobject = new ilPaymentObject($this->user_obj, $entry['pobject_id']);
         $price = ilPaymentPrices::_getPrice($entry['price_id']);
         if (!empty($_SESSION['coupons'][$coupon_session])) {
             $entry['math_price'] = $entry['price'];
             // (float) ilPaymentPrices::_getPriceFromArray($price);
             foreach ($_SESSION['coupons'][$coupon_session] as $key => $coupon) {
                 $this->coupon_obj->setId($coupon['pc_pk']);
                 $this->coupon_obj->setCurrentCoupon($coupon);
                 if ($this->coupon_obj->isObjectAssignedToCoupon($pobject->getRefId())) {
                     $_SESSION['coupons'][$coupon_session][$key]['total_objects_coupon_price'] += $entry['price'];
                     //(float) ilPaymentPrices::_getPriceFromArray($price);
                     $_SESSION['coupons'][$coupon_session][$key]['items'][] = $entry;
                 }
             }
         }
         unset($pobject);
     }
     $coupon_discount_items = $sc_obj->calcDiscountPrices($_SESSION['coupons'][$coupon_session]);
     foreach ($items as $entry) {
         $pobject = new ilPaymentObject($this->user_obj, $entry['pobject_id']);
         $price = ilPaymentPrices::_getPrice($entry['price_id']);
         if (array_key_exists($entry['pobject_id'], $coupon_discount_items)) {
             $bonus = $coupon_discount_items[$entry['pobject_id']]['math_price'] - $coupon_discount_items[$entry['pobject_id']]['discount_price'];
         }
         $booking_obj->setPobjectId($entry['pobject_id']);
         $booking_obj->setCustomerId($this->user_obj->getId());
         $booking_obj->setVendorId($pobject->getVendorId());
         $booking_obj->setPayMethod($pobject->getPayMethod());
         $booking_obj->setOrderDate(time());
         $booking_obj->setDuration($price['duration']);
         $booking_obj->setPrice(ilPaymentPrices::_getPriceString($entry['price_id']));
         $booking_obj->setDiscount($bonus > 0 ? -1 * $bonus : 0);
         $booking_obj->setPayed(1);
         $booking_obj->setAccess(1);
         switch ($price['price_type']) {
             case ilPaymentPrices::TYPE_UNLIMITED_DURATION:
                 $booking_obj->setDuration(0);
                 break;
             case ilPaymentPrices::TYPE_DURATION_MONTH:
                 $booking_obj->setDuration($price['duration']);
                 break;
             case ilPaymentPrices::TYPE_DURATION_DATE:
                 $booking_obj->setAccessStartdate($price['duration_from']);
                 $booking_obj->setAccessEnddate($price['duration_until']);
                 break;
         }
         $booking_obj->setAccessExtension($price['extension']);
         $obj_id = $ilObjDataCache->lookupObjId($pobject->getRefId());
         $obj_title = $ilObjDataCache->lookupTitle($obj_id);
         $oVAT = new ilShopVats((int) $pobject->getVatId());
         $obj_vat_rate = $oVAT->getRate();
         if ($bonus > 0) {
             $tmp_price = $booking_obj->getPrice() - $bonus;
             $obj_vat_unit = $pobject->getVat($tmp_price);
         } else {
             $obj_vat_unit = $pobject->getVat($booking_obj->getPrice());
         }
         $booking_obj->setObjectTitle($obj_title);
         $booking_obj->setVatRate($obj_vat_rate);
         $booking_obj->setVatUnit($obj_vat_unit);
         if (ilPaymethods::_EnabledSaveUserAddress($booking_obj->getPayMethod())) {
             $booking_obj->setStreet($this->user_obj->getStreet(), $this->user_obj->getHouseNumber);
             $booking_obj->setZipcode($this->user_obj->getZipcode());
             $booking_obj->setCity($this->user_obj->getCity());
             $booking_obj->setCountry($this->user_obj->getCountry());
         }
         $current_booking_id = $booking_obj->add();
         if ($current_booking_id) {
             $sc_obj->delete($entry['psc_id']);
             if (!empty($_SESSION['coupons'][$coupon_session])) {
                 foreach ($_SESSION['coupons'][$coupon_session] as $coupon) {
                     $this->coupon_obj->setId($coupon['pc_pk']);
                     $this->coupon_obj->setCurrentCoupon($coupon);
                     if ($this->coupon_obj->isObjectAssignedToCoupon($pobject->getRefId())) {
                         $this->coupon_obj->addCouponForBookingId($current_booking_id);
                     }
                 }
             }
         }
         unset($current_booking_id);
         unset($pobject);
     }
     if (!empty($_SESSION['coupons'][$coupon_session])) {
         foreach ($_SESSION['coupons'][$coupon_session] as $coupon) {
             $this->coupon_obj->setId($coupon['pc_pk']);
             $this->coupon_obj->setCurrentCoupon($coupon);
             $this->coupon_obj->addTracking();
         }
     }
 }
    private function __read()
    {
        global $ilUser;
        include_once './Services/Payment/classes/class.ilPaymentPrices.php';
        $this->sc_entries = array();
        if (ANONYMOUS_USER_ID == $ilUser->getId()) {
            $res = $this->db->queryf('
				SELECT * FROM payment_shopping_cart
				WHERE session_id = %s', array('text'), array($this->getSessionId()));
        } else {
            $res = $this->db->queryf('
				SELECT * FROM payment_shopping_cart
				WHERE customer_id = %s', array('integer'), array($this->user_obj->getId()));
        }
        while ($row = $this->db->fetchObject($res)) {
            $this->sc_entries[$row->psc_id]["psc_id"] = $row->psc_id;
            $this->sc_entries[$row->psc_id]["customer_id"] = $row->customer_id;
            $this->sc_entries[$row->psc_id]["pobject_id"] = $row->pobject_id;
            $this->sc_entries[$row->psc_id]["price_id"] = $row->price_id;
            $this->sc_entries[$row->psc_id]['session_id'] = $row->session_id;
        }
        // Delete all entries with not valid prices or pay_method
        unset($prices);
        $prices = array();
        foreach ($this->sc_entries as $entry) {
            // check if price_id exists for pobject
            if (!ilPaymentPrices::_priceExists($entry['price_id'], $entry['pobject_id'])) {
                $this->delete($entry['psc_id']);
                return false;
            }
            // check pay method
            $tmp_pobj = new ilPaymentObject($this->user_obj, $entry['pobject_id']);
            $pay_method = $tmp_pobj->getPayMethod();
            if ($pay_method == $tmp_pobj->PAY_METHOD_NOT_SPECIFIED) {
                $this->delete($entry['psc_id']);
                return false;
            }
            // if payment is expired
            if ($tmp_pobj->getStatus() == $tmp_pobj->STATUS_EXPIRES) {
                $this->delete($entry['psc_id']);
                return false;
            }
            $this->sc_entries[$entry['psc_id']]['pay_method'] = $pay_method;
            $prices[] = array('id' => $entry['price_id'], 'pay_method' => $pay_method);
            unset($tmp_pobj);
        }
        // set total amount
        $this->setTotalAmount(ilPaymentPrices::_getTotalAmount($prices ? $prices : array()));
        $this->setPobjectId($entry['pobject_id']);
        return true;
    }