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