/**
  * Set value by array
  *
  * @param	array	$a_values	value array
  */
 function setValueByArray($a_values)
 {
     if (isset($a_values[$this->getPostVar()]["date"]) && is_array($a_values[$this->getPostVar()]["date"])) {
         if (@checkdate($a_values[$this->getPostVar()]["date"]['m'], $a_values[$this->getPostVar()]["date"]['d'], $a_values[$this->getPostVar()]["date"]['y'])) {
             parent::setValueByArray($a_values);
             return;
         }
     } elseif (is_array($a_values[$this->getPostVar()]) && isset($a_values[$this->getPostVar()]["date"]) && !is_array($a_values[$this->getPostVar()]["date"])) {
         $this->setDate(new ilDate($a_values[$this->getPostVar()]["date"], IL_CAL_DATE));
     } else {
         if (!is_array($a_values[$this->getPostVar()]) && strlen($a_values[$this->getPostVar()])) {
             $this->setDate(new ilDate($a_values[$this->getPostVar()], IL_CAL_DATE));
         } else {
             $this->date = null;
         }
     }
     foreach ($this->getSubItems() as $item) {
         $item->setValueByArray($a_values);
     }
 }
 public function statisticObject()
 {
     global $rbacsystem, $ilToolbar, $ilObjDataCache;
     include_once './Services/Payment/classes/class.ilPayMethods.php';
     // MINIMUM ACCESS LEVEL = 'read'
     if (!$rbacsystem->checkAccess('read', $this->object->getRefId())) {
         $this->ilErr->raiseError($this->lng->txt('msg_no_perm_read'), $this->ilErr->MESSAGE);
     }
     $ilToolbar->addButton($this->lng->txt('paya_add_customer'), $this->ctrl->getLinkTarget($this, 'showObjectSelector'));
     if ($_POST['updateView'] == 1) {
         $_SESSION['pay_statistics']['show_filter'] = $_POST['show_filter'];
         $_SESSION['pay_statistics']['updateView'] = true;
         $_SESSION['pay_statistics']['until_check'] = $_POST['until_check'];
         $_SESSION['pay_statistics']['from_check'] = $_POST['from_check'];
         $_SESSION['pay_statistics']['transaction_type'] = isset($_POST['transaction_type']) ? $_POST['transaction_type'] : '';
         $_SESSION['pay_statistics']['transaction_value'] = isset($_POST['transaction_value']) ? $_POST['transaction_value'] : '';
         $_SESSION['pay_statistics']['adm_filter_title_id'] = (int) $_POST['adm_filter_title_id'];
         if ($_SESSION['pay_statistics']['from_check'] == '1') {
             $_SESSION['pay_statistics']['from']['date']['d'] = $_POST['from']['date']['d'];
             $_SESSION['pay_statistics']['from']['date']['m'] = $_POST['from']['date']['m'];
             $_SESSION['pay_statistics']['from']['date']['y'] = $_POST['from']['date']['y'];
         } else {
             $_SESSION['pay_statistics']['from']['date']['d'] = '';
             $_SESSION['pay_statistics']['from']['date']['m'] = '';
             $_SESSION['pay_statistics']['from']['date']['y'] = '';
         }
         if ($_SESSION['pay_statistics']['until_check'] == '1') {
             $_SESSION['pay_statistics']['til']['date']['d'] = $_POST['til']['date']['d'];
             $_SESSION['pay_statistics']['til']['date']['m'] = $_POST['til']['date']['m'];
             $_SESSION['pay_statistics']['til']['date']['y'] = $_POST['til']['date']['y'];
         } else {
             $_SESSION['pay_statistics']['til']['date']['d'] = '';
             $_SESSION['pay_statistics']['til']['date']['m'] = '';
             $_SESSION['pay_statistics']['til']['date']['y'] = '';
         }
         $_SESSION['pay_statistics']['payed'] = $_POST['payed'];
         $_SESSION['pay_statistics']['access'] = $_POST['access'];
         $_SESSION['pay_statistics']['pay_method'] = $_POST['pay_method'];
         $_SESSION['pay_statistics']['customer'] = isset($_POST['customer']) ? $_POST['customer'] : '';
         $_SESSION['pay_statistics']['vendor'] = isset($_POST['vendor']) ? $_POST['vendor'] : '';
     }
     $this->tpl->addBlockfile('ADM_CONTENT', 'adm_content', 'tpl.main_view.html', 'Services/Payment');
     $filter_form = new ilPropertyFormGUI();
     $filter_form->setFormAction($this->ctrl->getFormAction($this));
     $filter_form->setTitle($this->lng->txt('pay_filter'));
     $filter_form->setId('formular');
     $filter_form->setTableWidth('100 %');
     //filter
     $o_hide_check = new ilCheckBoxInputGUI($this->lng->txt('show_filter'), 'show_filter');
     $o_hide_check->setValue(1);
     $o_hide_check->setChecked($_POST['show_filter'] ? 1 : 0);
     $o_hidden = new ilHiddenInputGUI('updateView');
     $o_hidden->setValue(1);
     $o_hidden->setPostVar('updateView');
     $o_hide_check->addSubItem($o_hidden);
     $o_transaction_type = new ilSelectInputGUI();
     $trans_option = array($this->lng->txt('pay_starting'), $this->lng->txt('pay_ending'));
     $trans_value = array('0', '1');
     $o_transaction_type->setTitle($this->lng->txt('paya_transaction'));
     $o_transaction_type->setOptions($trans_option);
     $o_transaction_type->setValue($_SESSION['pay_statistics']['transaction_type']);
     $o_transaction_type->setPostVar('transaction_type');
     $o_hide_check->addSubItem($o_transaction_type);
     $o_transaction_val = new ilTextInputGUI();
     $o_transaction_val->setValue($_SESSION['pay_statistics']['transaction_value']);
     $o_transaction_val->setPostVar('transaction_value');
     $o_hide_check->addSubItem($o_transaction_val);
     $o_customer = new ilTextInputGUI();
     $o_customer->setTitle($this->lng->txt('paya_customer'));
     $o_customer->setValue($_SESSION['pay_statistics']['customer']);
     $o_customer->setPostVar('customer');
     $o_hide_check->addSubItem($o_customer);
     $o_vendor = new ilTextInputGUI();
     $o_vendor->setTitle($this->lng->txt('paya_vendor'));
     $o_vendor->setValue($_SESSION['pay_statistics']['vendor']);
     $o_vendor->setPostVar('vendor');
     $o_hide_check->addSubItem($o_vendor);
     $o_from_check = new ilCheckBoxInputGUI($this->lng->txt('pay_order_date_from'), 'from_check');
     $o_from_check->setValue(1);
     $o_from_check->setChecked($_SESSION['pay_statistics']['from_check'] ? 1 : 0);
     $o_date_from = new ilDateTimeInputGUI();
     $o_date_from->setPostVar('from');
     if ($_SESSION['pay_statistics']['from_check'] == '1') {
         $o_date_from->setValueByArray($_SESSION['pay_statistics']['from']);
         $o_date_from->checkInput();
     }
     $o_from_check->addSubItem($o_date_from);
     $o_hide_check->addSubItem($o_from_check);
     $o_until_check = new ilCheckBoxInputGUI($this->lng->txt('pay_order_date_til'), 'until_check');
     $o_until_check->setValue(1);
     $o_until_check->setChecked($_SESSION['pay_statistics']['until_check'] ? 1 : 0);
     $o_date_until = new ilDateTimeInputGUI();
     $o_date_until->setPostVar('til');
     if ($_SESSION['pay_statistics']['until_check'] == '1') {
         $o_date_until->setValueByArray($_SESSION['pay_statistics']['til']);
         $o_date_until->checkInput();
     }
     $o_until_check->addSubItem($o_date_until);
     $o_hide_check->addSubItem($o_until_check);
     // title filter
     $this->__initBookingObject();
     $title_options['all'] = $this->lng->txt('pay_all');
     $unique_titles = $this->booking_obj->getUniqueTitles();
     if (is_array($unique_titles) && count($unique_titles)) {
         foreach ($unique_titles as $ref_id) {
             $title_options[$ref_id] = $ilObjDataCache->lookupTitle($ilObjDataCache->lookupObjId($ref_id));
         }
     }
     $o_object_title = new ilSelectInputGUI();
     $o_object_title->setTitle($this->lng->txt('title'));
     $o_object_title->setOptions($title_options);
     $o_object_title->setValue($_SESSION["pay_statistics"]["adm_filter_title_id"]);
     $o_object_title->setPostVar('adm_filter_title_id');
     $o_hide_check->addSubItem($o_object_title);
     $o_payed = new ilSelectInputGUI();
     $payed_option = array('all' => $this->lng->txt('pay_all'), '1' => $this->lng->txt('yes'), '0' => $this->lng->txt('no'));
     $o_payed->setTitle($this->lng->txt('paya_payed'));
     $o_payed->setOptions($payed_option);
     $o_payed->setValue($_SESSION['pay_statistics']['payed']);
     $o_payed->setPostVar('payed');
     $o_hide_check->addSubItem($o_payed);
     $o_access = new ilSelectInputGUI();
     $access_option = array('all' => $this->lng->txt('pay_all'), '1' => $this->lng->txt('yes'), '0' => $this->lng->txt('no'));
     $o_access->setTitle($this->lng->txt('paya_access'));
     $o_access->setOptions($access_option);
     $o_access->setValue($_SESSION['pay_statistics']['access']);
     $o_access->setPostVar('access');
     $o_hide_check->addSubItem($o_access);
     $o_paymethod = new ilSelectInputGUI();
     $o_paymethod->setTitle($this->lng->txt('payment_system'));
     $o_paymethod->setOptions(ilPaymethods::getPayMethodsOptions('all'));
     $o_paymethod->setValue($_SESSION['pay_statistics']['pay_method']);
     $o_paymethod->setPostVar('pay_method');
     $o_hide_check->addSubItem($o_paymethod);
     $filter_form->addCommandButton('statistic', $this->lng->txt('pay_update_view'));
     $filter_form->addCommandButton('resetFilter', $this->lng->txt('pay_reset_filter'));
     $filter_form->addItem($o_hide_check);
     $this->tpl->setVariable('FORM', $filter_form->getHTML());
     //else 	$filter_form->checkInput();
     // STATISTICS TABLE
     $this->__initBookingObject();
     if (!count($bookings = $this->booking_obj->getBookings())) {
         ilUtil::sendInfo($this->lng->txt('paya_no_bookings'));
         return true;
     }
     #		else
     #		{
     #			$this->__showButton('exportVendors',$this->lng->txt('excel_export'));
     #		}
     include_once 'Services/User/classes/class.ilObjUser.php';
     $object_title_cache = array();
     $user_title_cache = array();
     $counter = 0;
     foreach ($bookings as $booking) {
         if (array_key_exists($booking['ref_id'], $object_title_cache)) {
             $tmp_obj = $object_title_cache[$booking['ref_id']];
         } else {
             $tmp_obj = ilObject::_lookupTitle(ilObject::_lookupObjId($booking['ref_id']));
             $object_title_cache[$booking['ref_id']] = $tmp_obj;
         }
         if (array_key_exists($booking['b_vendor_id'], $user_title_cache)) {
             $tmp_vendor = $user_title_cache[$booking['b_vendor_id']];
         } else {
             $tmp_vendor = ilObjUser::_lookupLogin($booking['b_vendor_id']);
             $user_title_cache[$booking['b_vendor_id']] = $tmp_vendor;
         }
         if (array_key_exists($booking['customer_id'], $user_title_cache)) {
             $tmp_purchaser = $user_title_cache[$booking['customer_id']];
         } else {
             if (ANONYMOUS_USER_ID == $booking['customer_id']) {
                 $tmp_purchaser = ilObjUser::_lookupLogin($booking['customer_id']);
                 $purchaser_name = $booking['name_extern'];
                 $tmp_purchaser_email = $booking['email_extern'];
             } else {
                 $tmp_purchaser = ilObjUser::_lookupLogin($booking['customer_id']);
                 $tmp_purchaser_name = ilObjUser::_lookupName($booking['customer_id']);
                 $purchaser_name = $tmp_purchaser_name['firstname'] . ' ' . $tmp_purchaser_name['lastname'];
                 $tmp_purchaser_email = ilObjUser::_lookupEmail($booking['customer_id']);
             }
             $user_title_cache[$booking['customer_id']] = $tmp_purchaser;
         }
         $transaction = $booking['transaction_extern'];
         $str_paymethod = ilPayMethods::getStringByPaymethod($booking['b_pay_method']);
         $transaction .= $booking['transaction'] . "<br> (" . $str_paymethod . ")";
         $f_result[$counter]['transaction'] = $transaction;
         $f_result[$counter]['object_title'] = $tmp_obj != '' ? $tmp_obj : $this->lng->txt('object_deleted');
         $f_result[$counter]['vendor'] = $tmp_vendor != '' ? '[' . $tmp_vendor . ']' : $this->lng->txt('user_deleted');
         $f_result[$counter]['customer'] = $tmp_purchaser != '' ? $purchaser_name . ' [' . $tmp_purchaser . ']<br>' . $tmp_purchaser_email : $this->lng->txt('user_deleted');
         $f_result[$counter]['order_date'] = ilDatePresentation::formatDate(new ilDate($booking['order_date'], IL_CAL_UNIX));
         if ($booking['duration'] == 0 && $booking['access_enddate'] == NULL) {
             $f_result[$counter]['duration'] = $this->lng->txt("unlimited_duration");
         } else {
             //				if($booking['duration'] > 0 )
             //				{
             //					$f_result[$counter]['duration'] = $booking['duration'].' '.$this->lng->txt('paya_months').' / </br>';
             //				}
             $f_result[$counter]['duration'] .= ilDatePresentation::formatDate(new ilDate($booking['access_startdate'], IL_CAL_DATETIME)) . ' - ' . ilDatePresentation::formatDate(new ilDate($booking['access_enddate'], IL_CAL_DATETIME));
         }
         $f_result[$counter]['price'] = $booking['price'] . ' ' . $booking['currency_unit'];
         $f_result[$counter]['discount'] = $booking['discount'] != '' ? $booking['discount'] . ' ' . $booking['currency_unit'] : '&nbsp;';
         $payed_access = $booking['payed'] ? $this->lng->txt('yes') : $this->lng->txt('no');
         $payed_access .= '/';
         $payed_access .= $booking['access_granted'] ? $this->lng->txt('yes') : $this->lng->txt('no');
         $f_result[$counter]['payed_access'] = $payed_access;
         $this->ctrl->setParameter($this, "booking_id", $booking['booking_id']);
         $link_change = "<div class=\"il_ContainerItemCommands\"><a class=\"il_ContainerItemCommand\" href=\"" . $this->ctrl->getLinkTarget($this, "editStatistic") . "\">" . $this->lng->txt("edit") . "</a></div>";
         $f_result[$counter]['edit'] = $link_change;
         unset($tmp_obj);
         unset($tmp_vendor);
         unset($tmp_purchaser);
         ++$counter;
     }
     return $this->__showStatisticTable($f_result);
 }