/** * Обработка и оплата операций * * @global type $DB * @param type $option * @return boolean */ function billingOperation($option, $transaction_id) { global $DB; $ok = false; $account = new account(); switch ($option['op_code']) { // Аккаунт ПРО у фрилансера case 48: case 49: case 50: case 51: case 76: // Удаляем операции по покупке ответов - публикуем ответы $prof = new payed(); $ok = $prof->SetOrderedTarif($this->uid, $transaction_id, 1, "Аккаунт PRO", $option['op_code'], $error); if ($ok) { $_SESSION['pro_last'] = payed::ProLast($_SESSION['login']); $_SESSION['pro_last'] = $_SESSION['pro_last']['freeze_to'] ? false : $_SESSION['pro_last']['cnt']; $userdata = new users(); $_SESSION['pro_test'] = $userdata->GetField($this->uid, $error2, 'is_pro_test', false); $this->clearBlockedOperations(step_freelancer::OFFERS_OP_CODE); $step_frl = new step_freelancer(); $offers = $step_frl->getWizardOffers($this->uid, 'all', false); if ($offers) { require_once $_SERVER['DOCUMENT_ROOT'] . "/classes/users.php"; $step_frl->log = $this->log; $step_frl->user = new users(); $step_frl->user->GetUserByUID($this->uid); $step_frl->transferOffers($offers); } $this->showProjectsFeedbacks(); } break; // Аккаунт ПРО у работодателя // Аккаунт ПРО у работодателя case 15: $prof = new payed(); $ok = $prof->SetOrderedTarif($this->uid, $transaction_id, 1, "Аккаунт PRO", $option['op_code'], $error); if ($ok) { $_SESSION['pro_last'] = payed::ProLast($_SESSION['login']); $_SESSION['pro_last'] = $_SESSION['pro_last']['freeze_to'] ? false : $_SESSION['pro_last']['cnt']; $userdata = new users(); $_SESSION['pro_test'] = $userdata->GetField($this->uid, $error2, 'is_pro_test', false); } // Обновляем выбор цвета для проектов тк он для ПРО бесплатный $colorProjects = $this->updateColorProject(); $prj = new new_projects(); foreach ($colorProjects as $k => $project) { $delete_color[] = $project['op_id']; if ($project['country'] == null) { $project['country'] = 'null'; } if ($project['city'] == null) { $project['city'] = 'null'; } $project['name'] = addslashes($project['name']); $project['descr'] = addslashes($project['descr']); if ($project['logo_id'] <= 0) { $project['logo_id'] = 'null'; } $project['payed_items'] = $project['payed_items'] | '010'; $project['is_color'] = 't'; $prj->editPrj($project, false); } // Удаляем данные операции if ($delete_color) { $this->deleteDraftAccountOperation($delete_color); } break; // Публикация конкурса // Публикация конкурса case new_projects::OPCODE_KON: case new_projects::OPCODE_KON_NOPRO: require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/wizard/step_wizard_registration.php'; $drafts = new drafts(); $draft = $drafts->getDraft($option['parent_id'], $this->uid, 1); // Если еще не опубликован if (!$draft['prj_id']) { $project_id = $draft['id']; $error = $account->Buy($bill_id, $transaction_id, $option['op_code'], $this->uid, $option['descr'], $option['comment'], 1, 0); $ok = $bill_id > 0; if ($bill_id) { $color = $DB->val("SELECT id FROM draft_account_operations WHERE parent_id = ? AND op_type = 'contest' AND option = 'color' AND uid = ?", $project_id, wizard::getUserIDReg()); $draft['billing_id'] = $bill_id; $draft['folder_id'] = 'null'; $draft['payed'] = '0'; $draft['payed_items'] = '000'; if (is_pro() && $color > 0) { $draft['is_color'] = 't'; } else { $draft['is_color'] = 'f'; } $draft['win_date'] = date('d-m-Y', strtotime($draft['win_date'])); $draft['end_date'] = date('d-m-Y', strtotime($draft['end_date'])); $draft['is_bold'] = 'f'; $draft['user_id'] = $this->uid; if ($draft['country'] == null) { $draft['country'] = 'null'; } if ($draft['city'] == null) { $draft['city'] = 'null'; } $draft['name'] = addslashes($draft['name']); $draft['descr'] = addslashes($draft['descr']); if ($draft['logo_id'] <= 0) { $draft['logo_id'] = 'null'; } $prj = new new_projects(); $attachedfiles_tmpdraft_files = drafts::getAttachedFiles($option['parent_id'], 4); if ($attachedfiles_tmpdraft_files) { $attachedfiles_tmpdraft_files = array_map(create_function('$a', 'return array("id" => $a);'), $attachedfiles_tmpdraft_files); } if ($attachedfiles_tmpdraft_files) { $month = date('Ym'); $dir = 'projects/upload/' . $month . '/'; $files = step_wizard_registration::transferFiles($attachedfiles_tmpdraft_files, 'file_projects', $dir); } $spec = $draft["categories"]; $spec = explode("|", $spec); $spec = array(array('category_id' => $spec[0], 'subcategory_id' => $spec[1])); $prj->addPrj($draft, $files); $prj->saveSpecs($draft["id"], $spec); // смотрим были ли выбраны платные опции для опубликованного конкурса if ($draft['id'] != $project_id && $draft['id'] > 0) { if ($this->sleep[$project_id]) { foreach ($this->sleep[$project_id] as $k => $opt) { $opt['parent_id'] = $draft['id']; $this->billingOperation($opt); } } else { //Обновляем родителя на всякий случай $update = array("parent_id" => $draft['id']); $DB->update("draft_account_operations", $update, "parent_id = ? AND op_type = 'contest' AND uid = ?", $project_id, wizard::getUserIDReg()); $this->sleep_parent[$project_id] = $draft['id']; } $DB->update("draft_projects", array('prj_id' => $draft['id']), "id = ? AND uid = ?", $project_id, wizard::getUserIDReg()); } } } break; // Платный проект/конкурс // Платный проект/конкурс case 53: $prj = new new_projects(); if ($this->sleep_parent[$option['parent_id']]) { $option['parent_id'] = $this->sleep_parent[$option['parent_id']]; } $project = $prj->getProject($option['parent_id']); if (!$project['id']) { $this->sleep[$option['parent_id']][$option['id']] = $option; return true; } else { unset($this->sleep[$option['parent_id']]); } if ($project['country'] == null) { $project['country'] = 'null'; } if ($project['city'] == null) { $project['city'] = 'null'; } $project['name'] = addslashes($project['name']); $project['descr'] = addslashes($project['descr']); if ($project['logo_id'] <= 0) { $project['logo_id'] = 'null'; } $project['folder_id'] = 'null'; $items = array(); switch ($option['option']) { case 'top': $project['top_days'] = $option['op_count']; break; case 'color': $is_pay = $project['payed_items'] & '010'; if ($is_pay != '010') { $project['payed_items'] = $project['payed_items'] | '010'; $project['is_color'] = 't'; $items['color'] = true; if (is_pro()) { $is_payed = true; $prj->SavePayedInfo($items, $project['id'], null, $project['top_days']); $prj->editPrj($project, false); } } else { $is_payed = true; } break; case 'bold': $is_pay = $project['payed_items'] & '001'; if ($is_pay != '001') { $project['payed_items'] = $project['payed_items'] | '001'; $project['is_bold'] = 't'; $items['bold'] = true; } else { $is_payed = true; } break; case 'logo': $is_pay = $project['payed_items'] & '100'; if ($is_pay != '100') { $key = md5(microtime()); $prj = new tmp_project($key); $prj->init(1); $fu = new CFile($option['src_id']); $ext = $fu->getext(); $tmp_dir = $prj->getDstAbsDir(); $tmp_name = $fu->secure_tmpname($tmp_dir, '.' . $ext); $tmp_name = substr_replace($tmp_name, "", 0, strlen($tmp_dir)); $fu->table = 'file_projects'; $r = $fu->_remoteCopy($tmp_dir . $tmp_name); $project['payed_items'] = $project['payed_items'] | '100'; $project['logo_id'] = $fu->id; $items['logo'] = true; if ($option['extra']) { $project['link'] = $option['extra']; } } else { $is_payed = true; } break; } if (!$is_payed) { $error = $account->Buy($bill_id, $transaction_id, $option['op_code'], $this->uid, $option['descr'], $option['comment'], $option['ammount'], 0); $ok = $bill_id > 0; $project['billing_id'] = $bill_id; $prj->SavePayedInfo($items, $project['id'], $bill_id, $project['top_days']); $prj->editPrj($project, false); } else { $ok = true; } break; // Платные ответы на проекты // Платные ответы на проекты case 61: $answers = new projects_offers_answers(); $error = $answers->BuyByFM($this->uid, $option['op_count'], $transaction_id, 0); if (!$error) { $ok = true; $_SESSION['answers_ammount'] = $option['op_count']; // Публикуем ответы $step_frl = new step_freelancer(); $offers = $step_frl->getWizardOffers($this->uid, $option['op_count']); if ($offers) { require_once $_SERVER['DOCUMENT_ROOT'] . "/classes/users.php"; $step_frl->log = $this->log; $step_frl->user = new users(); $step_frl->user->GetUserByUID($this->uid); $step_frl->transferOffers($offers); } } break; } return $ok; }
function initFromDraft($draft_id, $uid) { require_once $_SERVER['DOCUMENT_ROOT'] . "/classes/drafts.php"; require_once $_SERVER['DOCUMENT_ROOT'] . "/classes/project_exrates.php"; $drafts = new drafts(); $this->_project = $drafts->getDraft($draft_id, $uid, 1); if (!$this->_project['id']) { return false; } if ($this->_project['logo_id'] > 0) { $this->_project['link'] = $this->_project['logo_link']; $LogoFile = new CFile($this->_project['logo_id']); $this->initLogo($LogoFile); } $cat = explode(",", $this->_project['categories']); foreach ($cat as $category) { list($cat_id, $subcat_id) = explode("|", $category); $categories[] = array('category_id' => $cat_id, 'subcategory_id' => $subcat_id); } $this->setCategories($categories); $pExrates = project_exrates::getAll(); if ($this->_project['currency'] === 0) { // USD $costRub = $this->_project['cost'] * $pExrates['24']; // бюджет в рублях } elseif ($this->_project['currency'] === 1) { // EURO $costRub = $this->_project['cost'] * $pExrates['34']; } else { // рубли $costRub = $this->_project['cost']; } $this->setCostRub($costRub); $this->_project['draft_id'] = $this->_project['id']; unset($this->_project['id']); $this->_project['user_id'] = $this->_project['uid']; $this->_project['is_pro'] = is_pro(true, $uid) ? 't' : 'f'; if ($this->_project['top_days'] > 0) { $this->setAddedTopDays($this->_project['top_days']); } if ($this->isKonkurs()) { $this->_project['end_date'] = date('d-m-Y', strtotime($this->_project['end_date'])); $this->_project['win_date'] = date('d-m-Y', strtotime($this->_project['win_date'])); } $attach = drafts::getAttachedFiles($draft_id, 4, $this->_project['uid']); if (!empty($attach)) { foreach ($attach as $file_id) { $ret[$file_id] = array('status' => 1, 'id' => $file_id); } $this->addAttachedFiles($ret, true); } return true; }
/** * Публикация черновика * * @param int $draft_id ID черновика * @param int $type Тип черновика * @param bool $is_edit false - публикация нового поста/прокта, true - публикация существующего поста/проекта */ function PostDraft($draft_id, $type, $is_edit = false) { $objResponse = new xajaxResponse(); session_start(); $draft_id = intval($draft_id); $uid = get_uid(false); if ($uid) { require_once $_SERVER['DOCUMENT_ROOT'] . "/classes/drafts.php"; $draft = drafts::getDraft($draft_id, $uid, $type); if ($draft) { switch ($type) { case 2: // Личка require_once $_SERVER['DOCUMENT_ROOT'] . "/classes/attachedfiles.php"; $attachedfiles = new attachedfiles($attachedfiles_session); $attachedfiles_tmpdraft_files = drafts::getAttachedFiles($draft_id, 3); if ($attachedfiles_tmpdraft_files) { $attachedfiles_draft_files = array(); foreach ($attachedfiles_tmpdraft_files as $attachedfiles_draft_file) { $attachedfiles_draft_files[] = $attachedfiles_draft_file; } $attachedfiles->setFiles($attachedfiles_draft_files); } $objResponse->assign("f_attachedfiles_session", "value", $attachedfiles->getSession()); $objResponse->assign("f_msg", "innerHTML", $draft['msg']); $objResponse->assign("f_msg_to", "value", $draft['to_login']); $objResponse->assign("f_draft_id", "value", $draft['id']); $objResponse->assign("f_to_login", "value", $draft['to_login']); $objResponse->script("var attrAction = document.createAttribute('action'); attrAction.value='/contacts/?from=" . $draft['to_login'] . "'; \$('f_frm').setAttributeNode(attrAction);"); $objResponse->script('$("f_frm").submit();'); break; case 3: // Блоги require_once $_SERVER['DOCUMENT_ROOT'] . "/classes/blogs.php"; $objResponse->assign("f_draft_id", "value", $draft['id']); $objResponse->assign("f_msg", "value", $draft['msgtext']); $objResponse->assign("f_yt_link", "value", $draft['yt_link']); if ($draft['is_close_comments'] == 't') { $objResponse->script('$("f_is_close_comments").set("checked",true);'); } if ($draft['is_private'] == 't') { $objResponse->script('$("f_is_private").set("checked",true);'); } $objResponse->assign("f_category", "value", $draft['category'] . '|0'); if ($is_edit) { $blogmsg = blogs::GetMsgInfo($draft['post_id'], $error, $perm); $objResponse->assign("f_msg_name", "value", $draft['title']); $objResponse->assign("f_tr", "value", $blogmsg['thread_id']); $objResponse->assign("f_olduser", "value", $blogmsg['fromuser_id']); $objResponse->assign("f_reply", "value", $draft['post_id']); $objResponse->assign("f_action", "value", 'change'); $objResponse->assign("f_msg_name", "value", $draft['title']); $objResponse->assign("f_draft_post_id", "value", $draft['post_id']); $objResponse->script("var attrAction = document.createAttribute('action'); attrAction.value='/blogs/view.php?id=" . $draft['post_id'] . "'; \$('f_frm').setAttributeNode(attrAction);"); } else { $objResponse->assign("f_name", "value", $draft['title']); $objResponse->assign("f_sub_ord", "value", 'new'); $objResponse->assign("f_action", "value", 'new_tr'); $objResponse->script("var attrAction = document.createAttribute('action'); attrAction.value='/blogs/viewgroup.php?gr=" . $draft['category'] . "&ord=new&tr='; \$('f_frm').setAttributeNode(attrAction);"); } require_once $_SERVER['DOCUMENT_ROOT'] . "/classes/attachedfiles.php"; $attachedfiles = new attachedfiles($attachedfiles_session); $attachedfiles_tmpdraft_files = drafts::getAttachedFiles($draft_id, 1); if ($attachedfiles_tmpdraft_files) { $attachedfiles_draft_files = array(); foreach ($attachedfiles_tmpdraft_files as $attachedfiles_draft_file) { $attachedfiles_draft_files[] = $attachedfiles_draft_file; } $attachedfiles->setFiles($attachedfiles_draft_files, 1); } $objResponse->assign("f_attachedfiles_session", "value", $attachedfiles->getSession()); $objResponse->assign("f_poll_question", "value", $draft['poll_question']); $objResponse->assign("f_poll_type", "value", $draft['poll_type']); $answers = $draft['poll_answers']; if (count($answers)) { $out = ''; foreach ($answers as $answer) { $out .= '<input type="hidden" value="' . htmlspecialchars($answer, ENT_QUOTES) . '" name="answers[]" />'; } $objResponse->assign("f_poll_answers", "innerHTML", $out); } $objResponse->script('$("f_frm").submit();'); break; case 4: // Сообщества $objResponse->assign("f_id", "value", $draft['commune_id']); $objResponse->assign("f_draft_id", "value", $draft['id']); $objResponse->assign("f_category_id", "value", intval($draft['category'])); $objResponse->assign("f_title", "value", $draft['title']); $objResponse->assign("f_msgtext", "value", $draft['msg']); $objResponse->assign("f_youtube_link", "value", $draft['yt_link']); if ($draft['close_comments'] == 't') { $objResponse->script('$("f_close_comments").set("checked",true);'); } if ($draft['is_private'] == 't') { $objResponse->script('$("f_is_private").set("checked",true);'); } if ($is_edit) { $objResponse->assign("f_draft_post_id", "value", $draft['post_id']); $objResponse->assign("f_top_id", "value", $draft['post_id']); $objResponse->assign("f_message_id", "value", $draft['post_id']); $objResponse->assign("f_page", "value", 0); $objResponse->script("var attrAction = document.createAttribute('action'); attrAction.value='" . getFriendlyURL('commune', $draft['post_id']) . "'; \$('f_frm').setAttributeNode(attrAction);"); $objResponse->assign("f_action", "value", "do.Edit.post"); } else { $objResponse->script("var attrAction = document.createAttribute('action'); attrAction.value='" . getFriendlyURL('commune_commune', $draft['commune_id']) . "#o'; \$('f_frm').setAttributeNode(attrAction);"); $objResponse->assign("f_action", "value", "do.Create.post"); } require_once $_SERVER['DOCUMENT_ROOT'] . "/classes/attachedfiles.php"; $attachedfiles = new attachedfiles($attachedfiles_session); if (!$is_edit) { $attachedfiles_tmpdraft_files = drafts::getAttachedFiles($draft_id, 2); if ($attachedfiles_tmpdraft_files) { $attachedfiles_draft_files = array(); foreach ($attachedfiles_tmpdraft_files as $attachedfiles_draft_file) { $attachedfiles_draft_files[] = $attachedfiles_draft_file; } $attachedfiles->setFiles($attachedfiles_draft_files, 1); } } $objResponse->assign("f_attachedfiles_session", "value", $attachedfiles->getSession()); $objResponse->assign("f_poll_question", "value", $draft['poll_question']); $objResponse->assign("f_poll_type", "value", $draft['poll_type']); $answers = $draft['poll_answers']; if (count($answers)) { $out = ''; foreach ($answers as $answer) { $out .= '<input type="hidden" value="' . htmlspecialchars($answer, ENT_QUOTES) . '" name="answers[]" />'; } $objResponse->assign("f_poll_answers", "innerHTML", $out); } $objResponse->script('$("f_frm").submit();'); break; } } } return $objResponse; }
</td> </tr> </table> </div> </div> </div> <script type="text/javascript"> (function () { var attachedfiles_list = new Array(); <?php require_once $_SERVER['DOCUMENT_ROOT'] . "/classes/attachedfiles.php"; $attachedfiles_session = $_POST['attachedfiles_session']; $attachedfiles = new attachedfiles($attachedfiles_session); if ($draft_id) { if (!$attachedfiles_session) { $attachedfiles_tmpdraft_files = drafts::getAttachedFiles($draft_id, 2); if ($attachedfiles_tmpdraft_files) { $attachedfiles_prj_files = array(); foreach ($attachedfiles_tmpdraft_files as $attachedfiles_draft_file) { $attachedfiles_draft_files[] = $attachedfiles_draft_file; } $attachedfiles->setFiles($attachedfiles_draft_files, 1); } } } else { if ($action == 'Edit.post' && !$alert) { $attachedfiles_tmpblog_files = commune::getAttachedFiles($top['id']); if ($attachedfiles_tmpblog_files) { $attachedfiles_blog_files = array(); foreach ($attachedfiles_tmpblog_files as $attachedfiles_blog_file) { $attachedfiles_blog_files[] = $attachedfiles_blog_file;
public function paidOperation($id) { global $DB; if (!$id) { return false; } require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/projects.php'; $operation = $DB->row('SELECT * FROM draft_account_operations WHERE id = ? AND status IS NULL', $id); $account = new account(); $this->_transactionId = $account->start_transaction($_SESSION['uid'], $this->_transactionId); switch ($operation['op_type']) { case 'project': $project = $DB->row('SELECT id, payed_info FROM projects WHERE id = ?i', $operation['parent']); if (!$project['id']) { return 'Ошибка обработки операции.'; } if ($account->sum >= $operation['ammount']) { if ($error = $account->Buy($bill_id, $this->_transactionId, $operation['op_code'], $_SESSION['uid'], trim($operations['descr'], '/'), trim($operations['comments'], '/'), 1, true)) { return $error; } } if (!$bill_id) { return 'Не хватает денег.'; } $update = array(); switch ($operation['option']) { case 'color': $update['is_color'] = true; $update['payed_items'] = $project['payed_info'] | '010'; break; case 'bold': $update['is_bold'] = true; $update['payed_items'] = $project['payed_info'] | '001'; break; case 'top': $update['top_from'] = date('d.m.Y H:i', strtotime('now')); $update['top_to'] = date('d.m.Y H:i', strtotime("now +{$operation['op_count']} day")); break; case 'logo': $update['logo_id'] = $operation['src_id']; $update['payed_items'] = $project['payed_info'] | '100'; break; } $update['billing_id'] = $bill_id; $DB->update('projects', $update, 'id = ?', $operation['parent']); header('Location: /bill/success/'); exit; break; case 'contest': // Публикация конкурса if ($account->sum >= $operation['ammount']) { if ($error = $account->Buy($bill_id, $this->_transactionId, $operation['op_code'], $_SESSION['uid'], trim($operations['descr'], '/'), trim($operations['comments'], '/'), 1, true)) { return $error; } } if (!$bill_id) { return 'Не хватает денег.'; } $key = md5(microtime()); $prj = new tmp_project($key); if (get_uid()) { $prj->init(1); } $draft = new drafts(); $project = $drafts->getDraft($operation['parent'], $_SESSION['uid'], 1); require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/attachedfiles.php'; $attachedfiles = new attachedfiles(); $attachedfiles_tmpdraft_files = drafts::getAttachedFiles($operation['parent'], 4); if ($attachedfiles_tmpdraft_files) { $attachedfiles_prj_files = array(); foreach ($attachedfiles_tmpdraft_files as $attachedfiles_draft_file) { $attachedfiles_draft_files[] = $attachedfiles_draft_file; } $attachedfiles->setFiles($attachedfiles_draft_files, 1); } $insert = array('user_id' => $_SESSION['uid'], 'name' => $project['name'], 'descr' => $project['descr'], 'kind' => $project['kind'], 'cost' => $project['cost'], 'currency' => $project['currency'], 'country' => $project['country'] > 0 ? $project['country'] : 'NULL', 'city' => $project['city'] > 0 ? $project['city'] : 'NULL', 'payed' => '0', 'pro_only' => $project['pro_only'], 'logo_id' => 'NULL', 'link' => $project['logo_link'], 'is_color' => 'f', 'is_bold' => 'f', 'billing_id' => 0, 'payed_items' => '000', 'folder_id' => 0, 'budget_type' => $project['budget_type'], 'priceby' => $project['priceby'], 'prefer_sbr' => $project['prefer_sbr'], 'end_date' => $project['p_end_date'], 'win_date' => $project['p_win_date']); if (!empty($project['categories'])) { $cat = explode('|', $project['categories']); $categories[0] = array('category_id' => intval($cat[0]), 'subcategory_id' => intval($cat[1])); } $create = $prj->addPrj($insert, $attachedfiles_draft_files, $categories); // Добавляем проект if ($create) { $drafts->DeleteDraft($draft_id, $uid, 1); header('Location: /bill/success/'); exit; } break; case 'account': // Покупка ПРО break; } }