00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00031 include_once './payment/classes/class.ilPaymentObject.php';
00032 include_once './payment/classes/class.ilPaymentBookings.php';
00033
00034 class ilPaymentObjectGUI extends ilPaymentBaseGUI
00035 {
00036 var $ctrl;
00037 var $lng;
00038 var $user_obj;
00039
00040 var $pobject = null;
00041
00042 function ilPaymentObjectGUI(&$user_obj)
00043 {
00044 global $ilCtrl,$lng;
00045
00046 $this->ctrl =& $ilCtrl;
00047 $this->ilPaymentBaseGUI();
00048 $this->user_obj =& $user_obj;
00049
00050 $this->lng =& $lng;
00051 $this->lng->loadLanguageModule('crs');
00052
00053 }
00057 function &executeCommand()
00058 {
00059 global $tree;
00060
00061 $cmd = $this->ctrl->getCmd();
00062 switch ($this->ctrl->getNextClass($this))
00063 {
00064
00065 default:
00066 if(!$cmd = $this->ctrl->getCmd())
00067 {
00068 $cmd = 'showObjects';
00069 }
00070 $this->$cmd();
00071 break;
00072 }
00073 }
00074
00075 function showObjects()
00076 {
00077 $this->showButton('showObjectSelector',$this->lng->txt('paya_sell_object'));
00078
00079 $this->tpl->addBlockfile('ADM_CONTENT','adm_content','tpl.paya_objects.html','payment');
00080
00081 if(!count($objects = ilPaymentObject::_getObjectsData($this->user_obj->getId())))
00082 {
00083 sendInfo($this->lng->txt('paya_no_objects_assigned'));
00084
00085 return true;
00086 }
00087
00088 $this->__initPaymentObject();
00089
00090 $img_change = "<img src=\"".ilUtil::getImagePath("edit.gif")."\" alt=\"".
00091 $this->lng->txt("edit")."\" title=\"".$this->lng->txt("edit").
00092 "\" border=\"0\" vspace=\"0\"/>";
00093
00094 $counter = 0;
00095 foreach($objects as $data)
00096 {
00097 $tmp_obj =& ilObjectFactory::getInstanceByRefId($data['ref_id']);
00098 $f_result[$counter][] = $tmp_obj->getTitle();
00099
00100
00101 switch($data['status'])
00102 {
00103 case $this->pobject->STATUS_BUYABLE:
00104 $f_result[$counter][] = $this->lng->txt('paya_buyable');
00105 break;
00106
00107 case $this->pobject->STATUS_NOT_BUYABLE:
00108 $f_result[$counter][] = $this->lng->txt('paya_not_buyable');
00109 break;
00110
00111 case $this->pobject->STATUS_EXPIRES:
00112 $f_result[$counter][] = $this->lng->txt('paya_expires');
00113 break;
00114 }
00115 switch($data['pay_method'])
00116 {
00117 case $this->pobject->PAY_METHOD_NOT_SPECIFIED:
00118 $f_result[$counter][] = $this->lng->txt('paya_pay_method_not_specified');
00119 break;
00120
00121 case $this->pobject->PAY_METHOD_BILL:
00122 $f_result[$counter][] = $this->lng->txt('pays_bill');
00123 break;
00124
00125 case $this->pobject->PAY_METHOD_BMF:
00126 $f_result[$counter][] = $this->lng->txt('pays_bmf');
00127 break;
00128
00129 case $this->pobject->PAY_METHOD_PAYPAL:
00130 $f_result[$counter][] = $this->lng->txt('pays_paypal');
00131 break;
00132 }
00133 $tmp_user =& ilObjectFactory::getInstanceByObjId($data['vendor_id']);
00134 $f_result[$counter][] = $tmp_user->getFullname().' ['.$tmp_user->getLogin().']';
00135
00136
00137
00138 $f_result[$counter][] = ilPaymentBookings::_getCountBookingsByObject($data['pobject_id']);
00139
00140
00141
00142 $this->ctrl->setParameter($this,"pobject_id",$data['pobject_id']);
00143 # $link_change = "<a href=\"".$this->ctrl->getLinkTarget($this,"editDetails")."\"> ".
00144 # $img_change."</a>";
00145 $link_change = "<div class=\"il_ContainerItemCommands\"><a class=\"il_ContainerItemCommand\" href=\"".$this->ctrl->getLinkTarget($this,"editDetails")."\">".$this->lng->txt("edit")."</a></div>";
00146
00147 $f_result[$counter][] = $link_change;
00148 unset($tmp_user);
00149 unset($tmp_obj);
00150
00151 ++$counter;
00152 }
00153
00154 return $this->__showObjectsTable($f_result);
00155 }
00156
00157 function editDetails($a_show_confirm = false)
00158 {
00159 if(!$_GET['pobject_id'])
00160 {
00161 sendInfo($this->lng->txt('paya_no_object_selected'));
00162
00163 $this->showObjects();
00164 return true;
00165 }
00166 $this->__initPaymentObject((int) $_GET['pobject_id']);
00167 $this->ctrl->setParameter($this,'pobject_id',(int) $_GET['pobject_id']);
00168
00169 $this->showButton('editDetails',$this->lng->txt('paya_edit_details'));
00170 $this->showButton('editPrices',$this->lng->txt('paya_edit_prices'));
00171 # $this->__showPayMethodLink();
00172
00173 $this->tpl->addBlockfile('ADM_CONTENT','adm_content','tpl.paya_edit.html','payment');
00174 $this->tpl->setVariable("DETAILS_FORMACTION",$this->ctrl->getFormAction($this));
00175
00176 if($a_show_confirm)
00177 {
00178 $this->tpl->setCurrentBlock("confirm_delete");
00179 $this->tpl->setVariable("CONFIRM_FORMACTION",$this->ctrl->getFormAction($this));
00180 $this->tpl->setVariable("TXT_CANCEL",$this->lng->txt('cancel'));
00181 $this->tpl->setVariable("CONFIRM_CMD",'performDelete');
00182 $this->tpl->setVariable("TXT_CONFIRM",$this->lng->txt('confirm'));
00183 $this->tpl->parseCurrentBlock();
00184 }
00185
00186
00187 $tmp_obj =& ilObjectFactory::getInstanceByRefId($this->pobject->getRefId());
00188
00189 $this->tpl->setVariable("TYPE_IMG",ilUtil::getImagePath('icon_'.$tmp_obj->getType().'_b.gif'));
00190 $this->tpl->setVariable("ALT_IMG",$this->lng->txt('obj_'.$tmp_obj->getType()));
00191 $this->tpl->setVariable("TITLE",$tmp_obj->getTitle());
00192 $this->tpl->setVariable("DESCRIPTION",$tmp_obj->getDescription());
00193 $this->tpl->setVariable("TXT_PATH",$this->lng->txt('path'));
00194 $this->tpl->setVariable("PATH",$this->__getHTMLPath($this->pobject->getRefId()));
00195 $this->tpl->setVariable("TXT_VENDOR",$this->lng->txt('paya_vendor'));
00196 $this->tpl->setVariable("VENDOR",$this->__showVendorSelector($this->pobject->getVendorId()));
00197 $this->tpl->setVariable("TXT_COUNT_PURCHASER",$this->lng->txt('paya_count_purchaser'));
00198 $this->tpl->setVariable("COUNT_PURCHASER",ilPaymentBookings::_getCountBookingsByObject((int) $_GET['pobject_id']));
00199 $this->tpl->setVariable("TXT_STATUS",$this->lng->txt('status'));
00200 $this->tpl->setVariable("STATUS",$this->__showStatusSelector());
00201 $this->tpl->setVariable("TXT_PAY_METHOD",$this->lng->txt('paya_pay_method'));
00202 $this->tpl->setVariable("PAY_METHOD",$this->__showPayMethodSelector());
00203
00204 $this->tpl->setVariable("INPUT_CMD",'updateDetails');
00205 $this->tpl->setVariable("INPUT_VALUE",$this->lng->txt('save'));
00206
00207 $this->tpl->setVariable("DELETE_CMD",'deleteObject');
00208 $this->tpl->setVariable("DELETE_VALUE",$this->lng->txt('delete'));
00209 }
00210
00211 function deleteObject()
00212 {
00213 include_once './payment/classes/class.ilPaymentBookings.php';
00214
00215 if(!$_GET['pobject_id'])
00216 {
00217 sendInfo($this->lng->txt('paya_no_object_selected'));
00218
00219 $this->showObjects();
00220 return true;
00221 }
00222 if(ilPaymentBookings::_getCountBookingsByObject((int) $_GET['pobject_id']))
00223 {
00224 sendInfo($this->lng->txt('paya_bookings_available'));
00225 $this->editDetails();
00226
00227 return false;
00228 }
00229 else
00230 {
00231 sendInfo($this->lng->txt('paya_sure_delete_object'));
00232 $this->editDetails(true);
00233
00234 return true;
00235 }
00236 }
00237
00238 function performDelete()
00239 {
00240 include_once './payment/classes/class.ilPaymentPrices.php';
00241 include_once './payment/classes/class.ilPaymentBillVendor.php';
00242
00243 if(!$_GET['pobject_id'])
00244 {
00245 sendInfo($this->lng->txt('paya_no_object_selected'));
00246
00247 $this->showObjects();
00248 return true;
00249 }
00250 $this->__initPaymentObject((int) $_GET['pobject_id']);
00251
00252
00253 $this->pobject->delete();
00254
00255
00256 $price_obj =& new ilPaymentPrices((int) $_GET['pobject_id']);
00257 $price_obj->deleteAllPrices();
00258 unset($price_obj);
00259
00260 $bv =& new ilPaymentBillVendor((int) $_GET['pobject_id']);
00261 $bv->delete();
00262 unset($bv);
00263
00264
00265 sendInfo($this->lng->txt('paya_deleted_object'));
00266
00267 $this->showObjects();
00268
00269 return true;
00270 }
00271
00272
00273
00274 function editPayMethod()
00275 {
00276 $this->__initPaymentObject((int) $_GET['pobject_id']);
00277
00278 switch($this->pobject->getPayMethod())
00279 {
00280 case $this->pobject->PAY_METHOD_NOT_SPECIFIED:
00281 sendInfo($this->lng->txt('paya_select_pay_method_first'));
00282 $this->editDetails();
00283
00284 return true;
00285 case $this->pobject->PAY_METHOD_BMF:
00286 sendInfo($this->lng->txt('paya_no_settings_necessary'));
00287 $this->editDetails();
00288
00289 return true;
00290 case $this->pobject->PAY_METHOD_PAYPAL:
00291 sendInfo($this->lng->txt('paya_no_settings_necessary'));
00292 $this->editDetails();
00293
00294 return true;
00295 }
00296
00297 $this->editDetails();
00298
00299 return true;
00300 }
00301 function editPrices($a_show_delete = false)
00302 {
00303 include_once './payment/classes/class.ilPaymentPrices.php';
00304 include_once './payment/classes/class.ilPaymentCurrency.php';
00305 include_once './classes/class.ilTableGUI.php';
00306 include_once './payment/classes/class.ilGeneralSettings.php';
00307
00308 $genSet = new ilGeneralSettings();
00309
00310 $_SESSION['price_ids'] = $_SESSION['price_ids'] ? $_SESSION['price_ids'] : array();
00311
00312 if(!$_GET['pobject_id'])
00313 {
00314 sendInfo($this->lng->txt('paya_no_object_selected'));
00315
00316 $this->showObjects();
00317 return true;
00318 }
00319 $this->ctrl->setParameter($this,'pobject_id',(int) $_GET['pobject_id']);
00320
00321 $this->showButton('editDetails',$this->lng->txt('paya_edit_details'));
00322 $this->showButton('editPrices',$this->lng->txt('paya_edit_prices'));
00323
00324 $this->__initPaymentObject((int) $_GET['pobject_id']);
00325 # $this->__showPayMethodLink();
00326
00327 $this->tpl->addBlockfile('ADM_CONTENT','adm_content','tpl.paya_edit_prices.html','payment');
00328
00329 $price_obj =& new ilPaymentPrices((int) $_GET['pobject_id']);
00330 $prices = $price_obj->getPrices();
00331
00332
00333 if(!count($prices))
00334 {
00335 sendInfo($this->lng->txt('paya_no_price_available'));
00336
00337 $this->tpl->setCurrentBlock("price_info");
00338 $this->tpl->setVariable("CONFIRM_FORMACTION",$this->ctrl->getFormAction($this));
00339 $this->tpl->setVariable("CONFIRM_CMD",'addPrice');
00340 $this->tpl->setVariable("TXT_CONFIRM",$this->lng->txt('paya_add_price'));
00341 $this->tpl->parseCurrentBlock();
00342
00343 return true;
00344 }
00345
00346 if($a_show_delete)
00347 {
00348 sendInfo($this->lng->txt('paya_sure_delete_selected_prices'));
00349
00350 $this->tpl->setCurrentBlock("cancel");
00351 $this->tpl->setVariable("CANCEL_CMD",'editPrices');
00352 $this->tpl->setVariable("TXT_CANCEL",$this->lng->txt('cancel'));
00353 $this->tpl->parseCurrentBlock();
00354
00355 $this->tpl->setCurrentBlock("price_info");
00356 $this->tpl->setVariable("CONFIRM_FORMACTION",$this->ctrl->getFormAction($this));
00357 $this->tpl->setVariable("CONFIRM_CMD",'performDeletePrice');
00358 $this->tpl->setVariable("TXT_CONFIRM",$this->lng->txt('paya_delete_price'));
00359 $this->tpl->parseCurrentBlock();
00360 }
00361
00362
00363 $tpl =& new ilTemplate('tpl.table.html',true,true);
00364
00365
00366 $tpl->setCurrentBlock("tbl_form_header");
00367
00368 $tpl->setVariable("FORMACTION",$this->ctrl->getFormAction($this));
00369 $tpl->parseCurrentBlock();
00370
00371 $tpl->addBlockfile("TBL_CONTENT", "tbl_content",'tpl.paya_edit_prices_row.html','payment');
00372
00373 $counter = 0;
00374 foreach($prices as $price)
00375 {
00376 $currency = ilPaymentCurrency::_getCurrency($price['currency']);
00377
00378 $tpl->setCurrentBlock("tbl_content");
00379 $tpl->setVariable("ROWCOL", ilUtil::switchColor($counter,"tblrow2","tblrow1"));
00380
00381 $tpl->setVariable("CHECKBOX",ilUtil::formCheckBox(in_array($price['price_id'],$_SESSION['price_ids']) ? 1 : 0,
00382 'price_ids[]',
00383 $price['price_id']));
00384 $tpl->setVariable("DURATION_NAME",'prices['.$price['price_id'].'][duration]');
00385 $tpl->setVariable("DURATION",$price['duration']);
00386 $tpl->setVariable("MONTH",$this->lng->txt('paya_months'));
00387 $tpl->setVariable("UNIT_NAME",'prices['.$price['price_id'].'][unit_value]');
00388 $tpl->setVariable("UNIT",$price['unit_value']);
00389 # $tpl->setVariable("SHORTFORM",$this->lng->txt('currency_'.$currency['unit']));
00390 $tpl->setVariable("SHORTFORM",$genSet->get("currency_unit"));
00391
00392 $tpl->setVariable("SUB_UNIT_NAME",'prices['.$price['price_id'].'][sub_unit_value]');
00393 $tpl->setVariable("SUB_UNIT",$price['sub_unit_value']);
00394 # $tpl->setVariable("SUB_UNIT_TXT",$this->lng->txt('currency_'.$currency['sub_unit']));
00395 $tpl->setVariable("SUB_UNIT_TXT",$genSet->get("currency_subunit"));
00396 $tpl->parseCurrentBlock();
00397
00398 ++$counter;
00399 }
00400
00401
00402 $tpl->setCurrentBlock("tbl_action_button");
00403 $tpl->setVariable("BTN_NAME","deletePrice");
00404 $tpl->setVariable("BTN_VALUE",$this->lng->txt("paya_delete_price"));
00405 $tpl->parseCurrentBlock();
00406
00407 $tpl->setCurrentBlock("plain_buttons");
00408 $tpl->setVariable("PBTN_NAME","updatePrice");
00409 $tpl->setVariable("PBTN_VALUE",$this->lng->txt("paya_update_price"));
00410 $tpl->parseCurrentBlock();
00411
00412 $tpl->setCurrentBlock("plain_buttons");
00413 $tpl->setVariable("PBTN_NAME","addPrice");
00414 $tpl->setVariable("PBTN_VALUE",$this->lng->txt("paya_add_price"));
00415 $tpl->parseCurrentBlock();
00416
00417
00418 $tpl->setCurrentBlock("tbl_action_row");
00419 $tpl->setVariable("TPLPATH",$this->tpl->tplPath);
00420 $tpl->setVariable("COLUMN_COUNTS",4);
00421 $tpl->setVariable("IMG_ARROW", ilUtil::getImagePath("arrow_downright.gif"));
00422 $tpl->parseCurrentBlock();
00423
00424
00425 $tbl = new ilTableGUI();
00426 $tbl->setTemplate($tpl);
00427
00428
00429 $tbl->setStyle('table','std');
00430
00431 $tmp_obj =& ilObjectFactory::getInstanceByRefId($this->pobject->getRefId());
00432
00433 $tbl->setTitle($tmp_obj->getTitle(),
00434 "icon_".$tmp_obj->getType()."_b.gif",
00435 $this->lng->txt("objs_".$tmp_obj->getType()));
00436 $tbl->setHeaderNames(array('',
00437 $this->lng->txt('duration'),
00438 $this->lng->txt('price_a'),
00439 ''));
00440 $tbl->setHeaderVars(array("",
00441 "duration",
00442 "price_unit",
00443 "price_sub_unit"),
00444 array("ref_id" => $this->cur_ref_id));
00445
00446
00447 $tbl->setLimit($_GET["limit"]);
00448 $tbl->setOffset($_GET["offset"]);
00449 $tbl->setMaxCount(count($price_obj->getPrices()));
00450
00451 $tbl->disable("sort");
00452
00453
00454 $tbl->render();
00455
00456 $this->tpl->setVariable("PRICES_TABLE",$tpl->get());
00457
00458 return true;
00459 }
00460
00461 function addPrice()
00462 {
00463 if(!$_GET['pobject_id'])
00464 {
00465 sendInfo($this->lng->txt('paya_no_object_selected'));
00466
00467 $this->showObjects();
00468 return true;
00469 }
00470
00471 include_once './payment/classes/class.ilGeneralSettings.php';
00472
00473 $genSet = new ilGeneralSettings();
00474
00475 $this->ctrl->setParameter($this,'pobject_id',(int) $_GET['pobject_id']);
00476
00477 $this->__initPaymentObject((int) $_GET['pobject_id']);
00478
00479 $this->showButton('editDetails',$this->lng->txt('paya_edit_details'));
00480 $this->showButton('editPrices',$this->lng->txt('paya_edit_prices'));
00481 # $this->__showPayMethodLink();
00482
00483 $this->tpl->addBlockfile('ADM_CONTENT','adm_content','tpl.paya_add_price.html','payment');
00484
00485 $this->tpl->setVariable("ADD_FORMACTION",$this->ctrl->getFormAction($this));
00486
00487 $tmp_obj =& ilObjectFactory::getInstanceByRefId($this->pobject->getRefId());
00488 $this->tpl->setVariable("TYPE_IMG",ilUtil::getImagePath('icon_'.$tmp_obj->getType().'_b.gif'));
00489 $this->tpl->setVariable("ALT_IMG",$this->lng->txt('obj_'.$tmp_obj->getType()));
00490 $this->tpl->setVariable("TITLE",$tmp_obj->getTitle());
00491 $this->tpl->setVariable("DESCRIPTION",$this->lng->txt('paya_add_price_title'));
00492
00493
00494 # $this->tpl->setVariable("TXT_PRICE_A",$this->lng->txt('currency_euro'));
00495 # $this->tpl->setVariable("TXT_PRICE_B",$this->lng->txt('currency_cent'));
00496 $this->tpl->setVariable("TXT_PRICE_A",$genSet->get("currency_unit"));
00497 $this->tpl->setVariable("TXT_PRICE_B",$genSet->get("currency_subunit"));
00498
00499 $this->tpl->setVariable("MONTH",$this->lng->txt('paya_months'));
00500 $this->tpl->setVariable("TXT_DURATION",$this->lng->txt('duration'));
00501 $this->tpl->setVariable("TXT_PRICE",$this->lng->txt('price_a'));
00502 $this->tpl->setVariable("CANCEL",$this->lng->txt('cancel'));
00503 $this->tpl->setVariable("ADD",$this->lng->txt('paya_add_price'));
00504
00505 $this->tpl->setVariable("DURATION",$_POST['duration']);
00506 $this->tpl->setVariable("UNIT_VALUE",$_POST['unit']);
00507 $this->tpl->setVariable("SUB_UNIT",$_POST['SUB_UNIT']);
00508
00509 return true;
00510 }
00511
00512 function performAddPrice()
00513 {
00514 if(!$_GET['pobject_id'])
00515 {
00516 sendInfo($this->lng->txt('paya_no_object_selected'));
00517
00518 $this->showObjects();
00519 return true;
00520 }
00521
00522 include_once './payment/classes/class.ilPaymentPrices.php';
00523 include_once './payment/classes/class.ilPaymentCurrency.php';
00524
00525 $currency = ilPaymentCurrency::_getAvailableCurrencies();
00526
00527 $prices =& new ilPaymentPrices((int) $_GET['pobject_id']);
00528
00529 $prices->setDuration($_POST['duration']);
00530 $prices->setUnitValue($_POST['unit']);
00531 $prices->setSubUnitValue($_POST['sub_unit']);
00532 $prices->setCurrency($currency[1]['currency_id']);
00533
00534 if(!$prices->validate())
00535 {
00536 sendInfo($this->lng->txt('paya_price_not_valid'));
00537 $this->addPrice();
00538
00539 return true;
00540 }
00541 $prices->add();
00542
00543 sendInfo($this->lng->txt('paya_added_new_price'));
00544 $this->editPrices();
00545
00546 return true;
00547 }
00548
00549
00550
00551 function performDeletePrice()
00552 {
00553 if(!$_GET['pobject_id'])
00554 {
00555 sendInfo($this->lng->txt('paya_no_object_selected'));
00556
00557 $this->showObjects();
00558 return true;
00559 }
00560
00561 if(!count($_SESSION['price_ids']))
00562 {
00563 sendInfo($this->lng->txt('paya_no_prices_selected'));
00564
00565 $this->editPrices();
00566 return true;
00567 }
00568 include_once './payment/classes/class.ilPaymentPrices.php';
00569
00570 $prices =& new ilPaymentPrices((int) $_GET['pobject_id']);
00571
00572 foreach($_SESSION['price_ids'] as $price_id)
00573 {
00574 $prices->delete($price_id);
00575 }
00576
00577
00578 if(!count($prices->getPrices()))
00579 {
00580 $this->__initPaymentObject((int) $_GET['pobject_id']);
00581
00582 $this->pobject->setStatus($this->pobject->STATUS_NOT_BUYABLE);
00583 $this->pobject->update();
00584
00585 sendInfo($this->lng->txt('paya_deleted_last_price'));
00586 }
00587 unset($prices);
00588 unset($_SESSION['price_ids']);
00589
00590 return $this->editPrices();
00591 }
00592
00593
00594 function deletePrice()
00595 {
00596 if(!$_GET['pobject_id'])
00597 {
00598 sendInfo($this->lng->txt('paya_no_object_selected'));
00599
00600 $this->showObjects();
00601 return true;
00602 }
00603
00604 if(!count($_POST['price_ids']))
00605 {
00606 sendInfo($this->lng->txt('paya_no_prices_selected'));
00607
00608 $this->editPrices();
00609 return true;
00610 }
00611 $_SESSION['price_ids'] = $_POST['price_ids'];
00612
00613 $this->editPrices(true);
00614 return true;
00615 }
00616
00617
00618
00619
00620 function updatePrice()
00621 {
00622 include_once './payment/classes/class.ilPaymentPrices.php';
00623
00624 if(!$_GET['pobject_id'])
00625 {
00626 sendInfo($this->lng->txt('paya_no_object_selected'));
00627
00628 $this->showObjects();
00629 return true;
00630 }
00631 $po =& new ilPaymentPrices((int) $_GET['pobject_id']);
00632
00633 $this->ctrl->setParameter($this,'pobject_id',(int) $_GET['pobject_id']);
00634
00635
00636 foreach($_POST['prices'] as $price_id => $price)
00637 {
00638 $old_price = $po->getPrice($price_id);
00639
00640 $po->setDuration($price['duration']);
00641 $po->setUnitValue($price['unit_value']);
00642 $po->setSubUnitValue($price['sub_unit_value']);
00643 $po->setCurrency($old_price['currency']);
00644
00645 if(!$po->validate())
00646 {
00647 $error = true;
00648 }
00649 }
00650 if($error)
00651 {
00652 sendInfo($this->lng->txt('paya_insert_only_numbers'));
00653
00654 $this->editPrices();
00655 return false;
00656 }
00657 foreach($_POST['prices'] as $price_id => $price)
00658 {
00659 $old_price = $po->getPrice($price_id);
00660
00661 $po->setDuration($price['duration']);
00662 $po->setUnitValue($price['unit_value']);
00663 $po->setSubUnitValue($price['sub_unit_value']);
00664 $po->setCurrency($old_price['currency']);
00665
00666 $po->update($price_id);
00667 }
00668 sendInfo($this->lng->txt('paya_updated_prices'));
00669 $this->editPrices();
00670
00671 return true;
00672 }
00673
00674
00675 function updateDetails()
00676 {
00677 if(!$_GET['pobject_id'])
00678 {
00679 sendInfo($this->lng->txt('paya_no_object_selected'));
00680
00681 $this->showObjects();
00682 return true;
00683 }
00684 $this->__initPaymentObject((int) $_GET['pobject_id']);
00685 $this->ctrl->setParameter($this,'pobject_id',(int) $_GET['pobject_id']);
00686
00687
00688 $old_pay_method = $this->pobject->getPayMethod();
00689 $old_status = $this->pobject->getStatus();
00690
00691
00692 if($old_status == $this->pobject->STATUS_NOT_BUYABLE and
00693 (int) $_POST['status'] != $old_status)
00694 {
00695
00696 switch((int) $_POST['pay_method'])
00697 {
00698 case $this->pobject->PAY_METHOD_NOT_SPECIFIED:
00699 sendInfo($this->lng->txt('paya_select_pay_method_first'));
00700 $this->editDetails();
00701
00702 return false;
00703
00704 case $this->pobject->PAY_METHOD_BILL:
00705 include_once './payment/classes/class.ilPaymentBillVendor.php';
00706
00707 $bill_vendor =& new ilPaymentBillVendor((int) $_GET['pobject_id']);
00708 if(!$bill_vendor->validate())
00709 {
00710 sendInfo($this->lng->txt('paya_select_pay_method_first'));
00711 $this->editDetails();
00712
00713 return false;
00714 }
00715 break;
00716
00717 default:
00718 ;
00719 }
00720
00721 include_once './payment/classes/class.ilPaymentPrices.php';
00722
00723 $prices_obj =& new ilPaymentPrices((int) $_GET['pobject_id']);
00724 if(!count($prices_obj->getPrices()))
00725 {
00726 sendInfo($this->lng->txt('paya_edit_prices_first'));
00727 $this->editDetails();
00728
00729 return false;
00730 }
00731 }
00732
00733
00734 $this->pobject->setStatus((int) $_POST['status']);
00735 $this->pobject->setVendorId((int) $_POST['vendor']);
00736 $this->pobject->setPayMethod((int) $_POST['pay_method']);
00737 $this->pobject->update();
00738
00739 sendInfo($this->lng->txt('paya_details_updated'));
00740 $this->editDetails();
00741
00742 return true;
00743 }
00744
00745 function showObjectSelector()
00746 {
00747 global $tree;
00748
00749 include_once './payment/classes/class.ilPaymentObjectSelector.php';
00750
00751 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.paya_object_selector.html",'payment');
00752 $this->showButton('showObjects',$this->lng->txt('back'));
00753
00754
00755 sendInfo($this->lng->txt("paya_select_object_to_sell"));
00756
00757 $exp = new ilPaymentObjectSelector($this->ctrl->getLinkTarget($this,'showObjectSelector'), strtolower(get_class($this)));
00758 $exp->setExpand($_GET["paya_link_expand"] ? $_GET["paya_link_expand"] : $tree->readRootId());
00759 $exp->setExpandTarget($this->ctrl->getLinkTarget($this,'showObjectSelector'));
00760
00761 $exp->setOutput(0);
00762
00763 $this->tpl->setVariable("EXPLORER",$exp->getOutput());
00764
00765 return true;
00766 }
00767
00768 function showSelectedObject()
00769 {
00770 if(!$_GET['sell_id'])
00771 {
00772 sendInfo($this->lng->txt('paya_no_object_selected'));
00773
00774 $this->showObjectSelector();
00775 return true;
00776 }
00777 $this->tpl->addBlockFile('ADM_CONTENT','adm_content','tpl.paya_selected_object.html','payment');
00778 $this->showButton('showObjectSelector',$this->lng->txt('back'));
00779
00780 $this->tpl->setVariable("TYPE_IMG",ilUtil::getImagePath('icon_pays.gif',false));
00781 $this->tpl->setVariable("ALT_IMG",$this->lng->txt('details'));
00782
00783 $this->ctrl->setParameter($this,'sell_id',$_GET['sell_id']);
00784 $this->tpl->setVariable("SO_FORMACTION",$this->ctrl->getFormAction($this));
00785 $this->tpl->setVariable("TXT_TITLE",$this->lng->txt('title'));
00786 $this->tpl->setVariable("TXT_DESCRIPTION",$this->lng->txt('description'));
00787 $this->tpl->setVariable("TXT_OWNER",$this->lng->txt('owner'));
00788 $this->tpl->setVariable("TXT_PATH",$this->lng->txt('path'));
00789 $this->tpl->setVariable("TXT_VENDOR",$this->lng->txt('paya_vendor'));
00790 $this->tpl->setVariable("BTN1_NAME",'showObjects');
00791 $this->tpl->setVariable("BTN1_VALUE",$this->lng->txt('cancel'));
00792 $this->tpl->setVariable("BTN2_NAME",'addObject');
00793 $this->tpl->setVariable("BTN2_VALUE",$this->lng->txt('next'));
00794
00795
00796 $this->tpl->setVariable("DETAILS",$this->lng->txt('details'));
00797
00798 if($tmp_obj =& ilObjectFactory::getInstanceByRefId($_GET['sell_id']))
00799 {
00800 $this->tpl->setVariable("TITLE",$tmp_obj->getTitle());
00801 $this->tpl->setVariable("DESCRIPTION",$tmp_obj->getDescription());
00802 $this->tpl->setVariable("OWNER",$tmp_obj->getOwnerName());
00803 $this->tpl->setVariable("PATH",$this->__getHTMLPath((int) $_GET['sell_id']));
00804 $this->tpl->setVariable("VENDOR",$this->__showVendorSelector());
00805 }
00806 return true;
00807 }
00808
00809 function addObject()
00810 {
00811 if(!$_GET['sell_id'])
00812 {
00813 sendInfo($this->lng->txt('paya_no_object_selected'));
00814
00815 $this->showObjectSelector();
00816 return true;
00817 }
00818 if(!(int) $_POST['vendor'])
00819 {
00820 sendInfo($this->lng->txt('paya_no_vendor_selected'));
00821
00822 $this->showSelectedObject();
00823 return true;
00824 }
00825 if(!ilPaymentObject::_isPurchasable($_GET['sell_id']))
00826 {
00827 sendInfo($this->lng->txt('paya_object_not_purchasable'));
00828
00829 $this->showObjectSelector();
00830 return true;
00831 }
00832
00833
00834 include_once './payment/classes/class.ilPaymentObject.php';
00835
00836 $p_obj =& new ilPaymentObject($this->user_obj);
00837
00838 $p_obj->setRefId((int) $_GET['sell_id']);
00839 $p_obj->setStatus($p_obj->STATUS_NOT_BUYABLE);
00840 $p_obj->setPayMethod($p_obj->PAY_METHOD_NOT_SPECIFIED);
00841 $p_obj->setVendorId((int) $_POST['vendor']);
00842
00843 if($new_id = $p_obj->add())
00844 {
00845 sendInfo($this->lng->txt('paya_added_new_object'));
00846
00847 $_GET['pobject_id'] = $new_id;
00848 $this->editDetails();
00849
00850 return true;
00851 }
00852 else
00853 {
00854 sendInfo($this->lng->txt('paya_err_adding_object'));
00855 $this->showObjects();
00856
00857 return false;
00858 }
00859 }
00860
00861
00862 function __showVendorSelector($a_selected = 0)
00863 {
00864 include_once './payment/classes/class.ilPaymentVendors.php';
00865
00866 $vendors = array();
00867 if(ilPaymentVendors::_isVendor($this->user_obj->getId()))
00868 {
00869 $vendors[] = $this->user_obj->getId();
00870 }
00871 if($vend = ilPaymentTrustees::_getVendorsForObjects($this->user_obj->getId()))
00872 {
00873 $vendors = array_merge($vendors,$vend);
00874 }
00875 foreach($vendors as $vendor)
00876 {
00877 $tmp_obj =& ilObjectFactory::getInstanceByObjId($vendor,false);
00878
00879 $action[$vendor] = $tmp_obj->getFullname().' ['.$tmp_obj->getLogin().']';
00880 }
00881
00882 return ilUtil::formSelect($a_selected,'vendor',$action,false,true);
00883 }
00884
00885 function __showStatusSelector()
00886 {
00887 $action = array();
00888 $action[$this->pobject->STATUS_NOT_BUYABLE] = $this->lng->txt('paya_not_buyable');
00889 $action[$this->pobject->STATUS_BUYABLE] = $this->lng->txt('paya_buyable');
00890 $action[$this->pobject->STATUS_EXPIRES] = $this->lng->txt('paya_expires');
00891
00892 return ilUtil::formSelect($this->pobject->getStatus(),'status',$action,false,true);
00893 }
00894
00895 function __showPayMethodSelector()
00896 {
00897 include_once './payment/classes/class.ilPayMethods.php';
00898
00899 $action = array();
00900
00901 $action[$this->pobject->PAY_METHOD_NOT_SPECIFIED] = $this->lng->txt('paya_pay_method_not_specified');
00902 if(ilPayMethods::_enabled('pm_bill'))
00903 {
00904 $action[$this->pobject->PAY_METHOD_BILL] = $this->lng->txt('pays_bill');
00905 }
00906 if(ilPayMethods::_enabled('pm_bmf'))
00907 {
00908 $action[$this->pobject->PAY_METHOD_BMF] = $this->lng->txt('pays_bmf');
00909 }
00910 if(ilPayMethods::_enabled('pm_paypal'))
00911 {
00912 $action[$this->pobject->PAY_METHOD_PAYPAL] = $this->lng->txt('pays_paypal');
00913 }
00914
00915
00916 return ilUtil::formSelect($this->pobject->getPayMethod(),'pay_method',$action,false,true);
00917 }
00918
00919 function __showPayMethodLink()
00920 {
00921 switch($this->pobject->getPayMethod())
00922 {
00923 case $this->pobject->PAY_METHOD_NOT_SPECIFIED:
00924 $this->showButton('editPayMethod',$this->lng->txt('paya_edit_pay_method'));
00925 break;
00926
00927 case $this->pobject->PAY_METHOD_BILL:
00928
00929 $this->ctrl->setParameterByClass('ilpaymentbilladmingui','pobject_id',(int) $_GET['pobject_id']);
00930 $this->tpl->addBlockfile("BUTTONS", "buttons", "tpl.buttons.html");
00931 $this->tpl->setCurrentBlock("btn_cell");
00932 $this->tpl->setVariable("BTN_LINK",$this->ctrl->getLinkTargetByClass('ilpaymentbilladmingui'));
00933 $this->tpl->setVariable("BTN_TXT",$this->lng->txt('paya_edit_pay_method'));
00934 $this->tpl->parseCurrentBlock();
00935 break;
00936
00937 case $this->pobject->PAY_METHOD_BMF:
00938 $this->showButton('editPayMethod',$this->lng->txt('paya_edit_pay_method'));
00939 break;
00940
00941 case $this->pobject->PAY_METHOD_PAYPAL:
00942 $this->showButton('editPayMethod',$this->lng->txt('paya_edit_pay_method'));
00943 break;
00944 }
00945 }
00946 function __showObjectsTable($a_result_set)
00947 {
00948
00949 $tbl =& $this->initTableGUI();
00950 $tpl =& $tbl->getTemplateObject();
00951
00952
00953 $tpl->setCurrentBlock("tbl_form_header");
00954
00955 $tpl->setVariable("FORMACTION",$this->ctrl->getFormAction($this));
00956 $tpl->parseCurrentBlock();
00957
00958
00959
00960
00961
00962
00963
00964
00965
00966
00967
00968
00969
00970
00971
00972
00973
00974
00975 $tbl->setTitle($this->lng->txt("objects"),"icon_pays.gif",$this->lng->txt("objects"));
00976 $tbl->setHeaderNames(array($this->lng->txt("title"),
00977 $this->lng->txt("status"),
00978 $this->lng->txt("paya_pay_method"),
00979 $this->lng->txt("paya_vendor"),
00980 $this->lng->txt("paya_count_purchaser"),
00981 ''));
00982 $header_params = $this->ctrl->getParameterArray($this,'');
00983 $tbl->setHeaderVars(array("title",
00984 "status",
00985 "pay_method",
00986 "vendor",
00987 "purchasers",
00988 "options"),$header_params);
00989
00990
00991
00992
00993
00994 $tbl->setColumnWidth(array("15%","15%","15%","20%","20%"));
00995
00996 # $this->setTableGUIBasicData($tbl,$a_result_set);
00997
00998 $offset = $_GET["offset"];
00999 $order = $_GET["sort_by"];
01000 $direction = $_GET["sort_order"] ? $_GET['sort_order'] : 'desc';
01001
01002 $tbl->setOrderColumn($order,'order_date');
01003 $tbl->setOrderDirection($direction);
01004 $tbl->setOffset($offset);
01005 $tbl->setLimit($_GET["limit"]);
01006 $tbl->setMaxCount(count($a_result_set));
01007 $tbl->setFooter("tblfooter",$this->lng->txt("previous"),$this->lng->txt("next"));
01008 $tbl->setData($a_result_set);
01009
01010 $tbl->render();
01011
01012 $this->tpl->setVariable("OBJECTS_TABLE",$tbl->tpl->get());
01013
01014 return true;
01015 }
01016
01017
01018 function __getHTMLPath($a_ref_id)
01019 {
01020 global $tree;
01021
01022 $path = $tree->getPathFull($a_ref_id);
01023 unset($path[0]);
01024
01025 foreach($path as $data)
01026 {
01027 $html .= $data['title'].' > ';
01028 }
01029 return substr($html,0,-2);
01030 }
01031
01032 function __initPaymentObject($a_pobject_id = 0)
01033 {
01034 include_once './payment/classes/class.ilPaymentObject.php';
01035
01036 $this->pobject =& new ilPaymentObject($this->user_obj,$a_pobject_id);
01037
01038 return true;
01039 }
01040 }
01041 ?>