00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00035 require_once "./classes/class.ilObjectGUI.php";
00036
00037 class ilPaymentPurchaseGUI extends ilObjectGUI
00038 {
00039 var $ctrl;
00040 var $ilias;
00041 var $lng;
00042 var $tpl;
00043
00044 var $object = null;
00045
00046 function ilPaymentPurchaseGUI($a_ref_id)
00047 {
00048 global $ilCtrl,$lng,$ilErr,$ilias,$tpl,$tree;
00049
00050 $this->ctrl =& $ilCtrl;
00051 $this->ctrl->saveParameter($this,array("ref_id"));
00052
00053 $this->ilErr =& $ilErr;
00054 $this->ilias =& $ilias;
00055
00056 $this->lng =& $lng;
00057 $this->lng->loadLanguageModule('payment');
00058
00059 $this->tpl =& $tpl;
00060
00061 $this->ref_id = $a_ref_id;
00062
00063 $this->object =& ilObjectFactory::getInstanceByRefId($this->ref_id);
00064 }
00065
00069 function &executeCommand()
00070 {
00071 $cmd = $this->ctrl->getCmd();
00072
00073 if (!$cmd = $this->ctrl->getCmd())
00074 {
00075 $cmd = "showDetails";
00076 }
00077
00078
00079 # if($this->ctrl->getTargetScript() == 'start_purchase.php')
00080 # {
00081 $this->__buildHeader();
00082 # }
00083 $this->$cmd();
00084 }
00085
00086 function showDetails()
00087 {
00088 $this->__initPaymentObject();
00089 $this->__initPricesObject();
00090 $this->__initShoppingCartObject();
00091
00092 $this->tpl->addBlockFile('ADM_CONTENT','adm_content','tpl.pay_purchase_details.html','payment');
00093
00094 if($this->pobject->getStatus() == $this->pobject->STATUS_EXPIRES)
00095 {
00096 sendInfo($this->lng->txt('pay_expires_info'));
00097
00098 return false;
00099 }
00100
00101 $prices = $this->price_obj->getPrices();
00102 $buyedObject = "";
00103 if($this->sc_obj->isInShoppingCart($this->pobject->getPobjectId()))
00104 {
00105 $buyedObject = $this->sc_obj->getEntry($this->pobject->getPobjectId());
00106 if (is_array($prices) &&
00107 count($prices) > 1)
00108 {
00109 sendInfo($this->lng->txt('pay_item_already_in_sc_choose_another'));
00110 }
00111 else
00112 {
00113 sendInfo($this->lng->txt('pay_item_already_in_sc'));
00114 }
00115
00116 $this->tpl->setCurrentBlock("shopping_cart");
00117 # $this->tpl->setVariable("LINK_GOTO_SHOPPING_CART", "payment/payment.php");
00118 $this->tpl->setVariable("LINK_GOTO_SHOPPING_CART", "ilias.php?cmdClass=ilpaymentgui&baseClass=ilPersonalDesktopGUI&cmd=showShoppingCart");
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129 $this->tpl->setVariable("TXT_GOTO_SHOPPING_CART", $this->lng->txt('pay_goto_shopping_cart'));
00130 # $this->tpl->setVariable("TXT_BUY", $this->lng->txt('pay_click_to_buy'));
00131 $this->tpl->parseCurrentBlock("shopping_cart");
00132 }
00133
00134 $this->ctrl->setParameter($this, "ref_id", $this->pobject->getRefId());
00135
00136 # if (!is_array($buyedObject) ||
00137 # (is_array($buyedObject) && is_array($prices) && count($prices) > 1))
00138 # {
00139 $this->tpl->setVariable("DETAILS_FORMACTION",$this->ctrl->getFormAction($this));
00140 $this->tpl->setVariable("TYPE_IMG",ilUtil::getImagePath('icon_'.$this->object->getType().'_b.gif'));
00141 $this->tpl->setVariable("ALT_IMG",$this->lng->txt('obj_'.$this->object->getType()));
00142 $this->tpl->setVariable("TITLE",$this->object->getTitle());
00143
00144
00145 $this->tpl->setVariable("TXT_INFO",$this->lng->txt('info'));
00146 switch($this->pobject->getPayMethod())
00147 {
00148 case $this->pobject->PAY_METHOD_BILL:
00149 $this->tpl->setVariable("INFO_PAY",$this->lng->txt('pay_bill'));
00150 $this->tpl->setVariable("INPUT_CMD",'getBill');
00151 $this->tpl->setVariable("INPUT_VALUE",$this->lng->txt('pay_get_bill'));
00152 break;
00153
00154 case $this->pobject->PAY_METHOD_BMF:
00155 $this->tpl->setVariable("INFO_PAY",$this->lng->txt('pay_info'));
00156 if (is_array($buyedObject))
00157 {
00158 if (is_array($prices) && count($prices) > 1)
00159 {
00160 $this->tpl->setVariable("INPUT_CMD",'addToShoppingCart');
00161 $this->tpl->setVariable("INPUT_VALUE",$this->lng->txt('pay_change_price'));
00162 }
00163 }
00164 else
00165 {
00166 $this->tpl->setVariable("INPUT_CMD",'addToShoppingCart');
00167 $this->tpl->setVariable("INPUT_VALUE",$this->lng->txt('pay_add_to_shopping_cart'));
00168 }
00169 break;
00170
00171 case $this->pobject->PAY_METHOD_PAYPAL:
00172 $this->tpl->setVariable("INFO_PAY",$this->lng->txt('pay_info'));
00173 if (is_array($buyedObject))
00174 {
00175 if (is_array($prices) && count($prices) > 1)
00176 {
00177 $this->tpl->setVariable("INPUT_CMD",'addToShoppingCart');
00178 $this->tpl->setVariable("INPUT_VALUE",$this->lng->txt('pay_change_price'));
00179 }
00180 }
00181 else
00182 {
00183 $this->tpl->setVariable("INPUT_CMD",'addToShoppingCart');
00184 $this->tpl->setVariable("INPUT_VALUE",$this->lng->txt('pay_add_to_shopping_cart'));
00185 }
00186 break;
00187 }
00188
00189 $this->tpl->setVariable("ROWSPAN",count($prices));
00190 $this->tpl->setVariable("TXT_PRICES",$this->lng->txt('prices'));
00191 # }
00192
00193 if (is_array($prices))
00194 {
00195 # if (count($prices) > 1)
00196 # {
00197 $counter = 0;
00198 foreach($prices as $price)
00199 {
00200 if ($counter == 0)
00201 {
00202 $placeholderCheckbox = "CHECKBOX";
00203 $placeholderDuration = "DURATION";
00204 $placeholderPrice = "PRICE";
00205 }
00206 else
00207 {
00208 $placeholderCheckbox = "ROW_CHECKBOX";
00209 $placeholderDuration = "ROW_DURATION";
00210 $placeholderPrice = "ROW_PRICE";
00211 }
00212 $this->tpl->setCurrentBlock("price_row");
00213 if ($buyedObject["price_id"] == $price['price_id'])
00214 {
00215 $this->tpl->setVariable($placeholderCheckbox,ilUtil::formRadioButton(1,'price_id',$price['price_id']));
00216 }
00217 else
00218 {
00219 $this->tpl->setVariable($placeholderCheckbox,ilUtil::formRadioButton(0,'price_id',$price['price_id']));
00220 }
00221 $this->tpl->setVariable($placeholderDuration,$price['duration'].' '.$this->lng->txt('paya_months'));
00222 $this->tpl->setVariable($placeholderPrice,ilPaymentPrices::_getPriceString($price['price_id']));
00223 $this->tpl->parseCurrentBlock();
00224 $counter++;
00225 }
00226 # }
00227 # else if (!is_array($buyedObject))
00228 # {
00229 # foreach($prices as $price)
00230 # {
00231 # $this->tpl->setVariable("CHECKBOX",ilUtil::formRadioButton(0,'price_id',$price['price_id']));
00232 # $this->tpl->setVariable("DURATION",$price['duration'].' '.$this->lng->txt('paya_months'));
00233 # $this->tpl->setVariable("PRICE",ilPaymentPrices::_getPriceString($price['price_id']));
00234 # }
00235 # }
00236 }
00237
00238 }
00239
00240 function addToShoppingCart()
00241 {
00242 if(!isset($_POST['price_id']))
00243 {
00244 sendInfo($this->lng->txt('pay_select_price'));
00245 $this->showDetails();
00246
00247 return true;
00248 }
00249 else
00250 {
00251 $this->__initPaymentObject();
00252 $this->__initShoppingCartObject();
00253
00254
00255 $this->sc_obj->setPriceId((int) $_POST['price_id']);
00256 $this->sc_obj->setPobjectId($this->pobject->getPobjectId());
00257 $this->sc_obj->add();
00258
00259 # $tmp_obj =& ilObjectFactory::getInstanceByRefId($this->pobject->getRefId());
00260
00261 $this->tpl->addBlockFile('ADM_CONTENT','adm_content','tpl.pay_purchase_details.html','payment');
00262 $this->tpl->setCurrentBlock("shopping_cart");
00263 # $this->tpl->setVariable("LINK_GOTO_SHOPPING_CART", "payment/payment.php");
00264 $this->tpl->setVariable("LINK_GOTO_SHOPPING_CART", "ilias.php?cmdClass=ilpaymentgui&baseClass=ilPersonalDesktopGUI&cmd=showShoppingCart");
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275 $this->tpl->setVariable("TXT_GOTO_SHOPPING_CART", $this->lng->txt('pay_goto_shopping_cart'));
00276 # $this->tpl->setVariable("TXT_BUY", $this->lng->txt('pay_click_to_buy'));
00277 $this->tpl->parseCurrentBlock("shopping_cart");
00278
00279 sendInfo($this->lng->txt('pay_added_to_shopping_cart'));
00280
00281 return true;
00282 }
00283 }
00284
00285
00286 function __initShoppingCartObject()
00287 {
00288 include_once './payment/classes/class.ilPaymentShoppingCart.php';
00289
00290 $this->sc_obj =& new ilPaymentShoppingCart($this->ilias->account);
00291
00292 return true;
00293 }
00294
00295 function __initPaymentObject()
00296 {
00297 include_once './payment/classes/class.ilPaymentObject.php';
00298
00299 $this->pobject =& new ilPaymentObject($this->ilias->account,ilPaymentObject::_lookupPobjectId($this->ref_id));
00300
00301 return true;
00302 }
00303 function __initPricesObject()
00304 {
00305 include_once './payment/classes/class.ilPaymentPrices.php';
00306
00307 $this->price_obj =& new ilPaymentPrices($this->pobject->getPobjectId());
00308
00309 return true;
00310 }
00311
00312 function __buildHeader()
00313 {
00314 $this->tpl->addBlockFile("CONTENT", "content", "tpl.payb_content.html");
00315
00316 $this->tpl->setVariable("HEADER",$this->object->getTitle());
00317 $this->tpl->setVariable("DESCRIPTION",$this->object->getDescription());
00318
00319 # $this->__buildStylesheet();
00320 # $this->__buildStatusline();
00321 }
00322
00323 function __buildStatusline()
00324 {
00325 $this->tpl->addBlockFile("STATUSLINE", "statusline", "tpl.statusline.html");
00326 $this->__buildLocator();
00327 }
00328
00329 function __buildLocator()
00330 {
00331 $this->tpl->addBlockFile("LOCATOR", "locator", "tpl.locator.html");
00332 $this->tpl->setVariable("TXT_LOCATOR",$this->lng->txt("locator"));
00333
00334 $this->tpl->setCurrentBlock("locator_item");
00335 $this->tpl->setVariable("ITEM", $this->lng->txt("repository"));
00336 $this->tpl->setVariable("LINK_ITEM", "../repository.php?getlast=true");
00337 $this->tpl->parseCurrentBlock();
00338
00339
00340 sendInfo();
00341
00342 return true;
00343 }
00344
00345 function __buildStylesheet()
00346 {
00347 $this->tpl->setVariable("LOCATION_STYLESHEET",ilUtil::getStyleSheetLocation());
00348 $this->tpl->setVariable("LOCATION_JAVASCRIPT",ilUtil::getJSPath('functions.js'));
00349 }
00350
00351
00352
00353 }
00354 ?>