function setActiveJS() { $v = (int) $this->request('v'); $itemId = (int) $this->request('c'); if ($itemId) { $item = new struct_corecatalog_delivery(array('rdl_id' => $itemId)); $item->load(); $item->rdl_active = (int) $v; $r = $item->save(); $r = ($v and $r) ? false : true; if ($r) { echo '$("active_del_link_' . $itemId . '_1").style.display="none";'; echo '$("active_del_link_' . $itemId . '_0").style.display="";'; } else { echo '$("active_del_link_' . $itemId . '_1").style.display="";'; echo '$("active_del_link_' . $itemId . '_0").style.display="none";'; } } else { $this->securityHoleAlert(__FILE__, __LINE__, $this->getClassName()); } }
/** * Final order! * return HTML to AJAX */ function order() { $isNewUser = false; $item = new struct_corecatalog_orders(); $item->order_userid = ($user = $this->getCurrentUser()) ? $user->u_id : 0; if ($this->_showCaptcha or $this->_OrderScheme[self::ORDER_REG]) { $captcha = new model_coresession_captcha(SITE_ALIAS); if (!$captcha->check($this->request('captcha_text'))) { $this->setVar('message', $this->lang('wrongcaptcha.session.error')); $this->startPage(); $this->setVar('wrong_capcha', true); return; } } $item->order_address = $this->request('address', ''); $item->order_comments = $this->request('order_comment'); $item->order_email = $this->getCurrentUser()->u_email ?: $this->request('email'); $item->order_fio = $this->request('fio'); $item->order_phone = $this->request('contact_phone'); $item->order_langid = $this->getCurrentLangID(); if ($this->request('delivery')) { $item->order_delivery = (int) $this->request('delivery'); } if ($item->order_userid === 0) { //type of the order - 3 is the quick order $item->order_type = 3; $isNewUser = true; } else { if ($this->_OrderScheme[self::ORDER_FAST_REG]) { //type of the order - 2 is the quick & registration $item->order_type = 2; } else { //type of the order - 1 is the registration $item->order_type = 1; } } $item->order_dt = now(); $item->order_num = date("ymdHis"); $item->order_num .= $this->getCurrentUser() ? 'u' . $this->getCurrentUser()->u_id : 's'; $item->order_sessid = $this->getCurrentSessID(); //Link to the tree_id $item->order_status = $this->_defStatus; //calc the order summ $model_bin = rad_instances::get('model_corecatalog_bin'); $ct_showing = $this->getParamsObject() ? $this->getParamsObject()->ct_showing : NULL; $items = $model_bin->getCartProducts(NULL, NULL, $ct_showing); $bin_pos = $model_bin->getItemsCart(); $counts = array(); $bin_ids = array(); $total_count = 0; $total_costs = 0; if (count($bin_pos)) { foreach ($bin_pos as $id) { $counts[$id->bp_catid] = $id->bp_count; $bin_ids[$id->bp_catid] = $id->bp_id; } } for ($i = 0; $i < count($items); $i++) { $items[$i]->cat_cost = model_corecatalog_currcalc::calcCours($items[$i]->cat_cost, $items[$i]->cat_currency_id); $items[$i]->cat_count = $counts[$items[$i]->cat_id]; $total_count += $items[$i]->cat_count; $total_costs += $items[$i]->cat_cost * $items[$i]->cat_count; $items[$i]->bp_id = $bin_ids[$items[$i]->cat_id]; } if ($this->_showDelivery and $this->request('delivery')) { $delivery = new struct_corecatalog_delivery(array('rdl_id' => (int) $this->request('delivery'))); $delivery->load(); $totalCostsWithoutDelivery = $total_costs; $total_costs += model_corecatalog_currcalc::calcCours($delivery->rdl_cost, $delivery->rdl_currency); $item->delivery = $delivery; } $item->order_summ = $total_costs; $item->order_currency = model_corecatalog_currcalc::$_curcours->cur_ind; $item->order_curid = model_corecatalog_currcalc::$_curcours->cur_id; if ($isNewUser && $this->_addtoclients) { //try, maybe user already exists $modelUsers = rad_instances::get('model_core_users'); $exUser = $modelUsers->setState('u_email', $item->order_email)->getItem(); if (!empty($exUser->u_id)) { $item->order_userid = (int) $exUser->u_id; $isNewUser = false; } else { $user = new struct_core_users(array('u_group' => $this->_clientsPID, 'u_login' => $item->order_email, 'u_email' => $item->order_email, 'u_fio' => $item->order_fio, 'u_phone' => $item->order_phone, 'u_address' => $item->order_address, 'u_isadmin' => 0)); $modelUsers->register($user, $this->config('registration.class') != 'registerphpbb'); $item->order_userid = $user->u_id; } } $model = rad_instances::get('model_corecatalog_order'); if ($rows = $model->insertItem($item)) { $item->order_id = $rows; $item->order_num .= $item->order_id; $item->save(); rad_instances::get('model_corecatalog_bin')->clearItemsCart(); /*assign to the referals*/ if ($this->config('referals.on') and class_exists('struct_coresession_referals_orders')) { //TODO Учесть что пользователь до этого уже приведен был другим партнером и взять с user_id if ($this->cookie($this->config('referals.cookieName')) or !empty($item->order_userid)) { if ($item->order_userid !== 0) { $refUser = rad_instances::get('model_coresession_referals')->getUserPartner($item->order_userid); } if (!empty($refUser->u_id)) { $referalId = $refUser->rru_referal_id; } elseif ($referal = rad_instances::get('model_coresession_referals')->setState('cookie', $this->cookie($this->config('referals.cookieName')))->getItem()) { $referalId = $referal->rrf_id; } if (!empty($referalId)) { $percent = rad_instances::get('model_coresession_referals')->getParntnerPercent($referalId); $orderSum = isset($totalCostsWithoutDelivery) ? $totalCostsWithoutDelivery : $item->order_summ; $refOfder = new struct_coresession_referals_orders(array('rro_referals_id' => $referalId, 'rro_order_id' => $item->order_id, 'rro_percent' => $percent, 'rro_currency_id' => $item->order_curid, 'rro_order_sum' => $orderSum)); rad_instances::get('model_coresession_referals')->insertOrder($refOfder); } } } } $item->order_positions = $bin_pos; if ($isNewUser) { $this->_sendMail($item, 'order_new'); } else { $this->_sendMail($item, 'order_new_auth'); } $this->redirect($this->makeURL('action=success')); }