/** * Регистрирует новое личное сообщение. * * @param int $user_id id пользователя-отправителя * @param string $target_login логин пользователя-получателя * @param string $text текст сообщения * @param array $files прикрепленные файлы * @param int $force разрешение/отказ ответа на письмо (1/0) * @param bool $skip_mail Если TRUE - не отправлять уведомление о новом сообщении на емайл. * @param string $attachedfiles_session ID сессии загруженных файлов * * @return mixed сообщение об ошибке и флаг ошибки в случае ее возниконовения */ public function Add($user_id, $target_login, $text, $files, $force = 0, $skip_mail = false, $attachedfiles_session = null, &$message_id = 0) { require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/users.php'; require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/ignor.php'; $users = new users(); $login = $users->GetName($user_id, $err); $tar_id = $users->GetUid($err, $target_login); if ((ignor::CheckIgnored($tar_id, $user_id) || in_array($target_login, array('admin', 'Anonymous'))) && !$force) { $error = 'Пользователь запретил отправлять ему сообщения'; } else { if ($files) { if (count($files) > self::MAX_FILES) { $alert[1] = 'Вы не можете прикрепить больше ' . self::MAX_FILES . ' файлов к сообщению.'; } else { $max_file_size = self::MAX_FILE_SIZE; foreach ($files as $file) { $ext = $file->getext(); $file->max_size = $max_file_size; $max_file_size -= $file->size; if (!in_array($ext, $GLOBALS['disallowed_array'])) { $f_name = $file->MoveUploadedFile($login['login'] . '/contacts'); if (!isNulArray($file->error)) { if ($max_file_size < 0) { $alert[1] = 'Вы превысили максимально допустимый размер файлов'; } else { $alert[1] = $GLOBALS['PDA'] ? 'Файл не удовлетворяет условиям загрузки' : 'Один или несколько файлов не удовлетворяют условиям загрузки.'; } break; } } else { $alert[1] = $GLOBALS['PDA'] ? 'Файл не удовлетворяет условиям загрузки' : 'Один или несколько файлов имеют неправильный формат.'; } } } } if (empty($alert) && empty($error)) { $memBuff = new memBuff(); // автоматические папки для массовых рассылок личных менеджеров global $aPmUserUids; if (in_array($tar_id, $aPmUserUids) || SERVER === 'local' || SERVER === 'beta' || SERVER === 'alpha') { $DBproxy = new DB(); $nRecId = $DBproxy->val('SELECT mess_pm_ustf_add(?i, ?i)', $tar_id, $user_id); if ($nRecId) { $memBuff->delete('pmAutoFolder' . $tar_id . '_' . $nRecId); } } //--------------------------------------------- $DB = new DB(); $f = array(); if ($files) { foreach ($files as $file) { $f[] = $file->id; } } require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/attachedfiles.php'; $attachedfiles = new attachedfiles($attachedfiles_session); $attachedfiles_files = $attachedfiles->getFiles(); if ($attachedfiles_files) { foreach ($attachedfiles_files as $attachedfiles_file) { $cFile = new CFile($attachedfiles_file['id']); $cFile->table = 'file'; $ext = $cFile->getext(); $tmp_dir = 'users/' . substr($login['login'], 0, 2) . '/' . $login['login'] . '/contacts/'; $tmp_name = $cFile->secure_tmpname($tmp_dir, '.' . $ext); $tmp_name = substr_replace($tmp_name, '', 0, strlen($tmp_dir)); $cFile->_remoteCopy($tmp_dir . $tmp_name, true); $f[] = $cFile->id; } } $attachedfiles->clear(); $aNoMod = array_merge($GLOBALS['aContactsNoMod'], $GLOBALS['aPmUserUids']); //$bNoMod = hasPermissions('streamnomod', $user_id) || hasPermissions('streamnomod', $tar_id) || is_pro(true, $user_id) || is_pro(true, $tar_id) || in_array($user_id, $aNoMod); $bNoMod = true; // #0022344: Убрать из потоков личку $message_id = $DB->val('SELECT messages_add(?i, ?i, ?, ?b, ?a, ?b)', $user_id, $tar_id, $text, $skip_mail, $f, $bNoMod); if ($user_id % 2 == $tar_id % 2) { $memBuff->delete(self::MEMBUFF_CHAT_PREFIX . $tar_id); } if ($message_id && !$skip_mail && !QChat::active($tar_id)) { $mail = new pmail(); $mail->NewMessage($user_id, $tar_id, stripslashes($text)); } if ($message_id) { require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/external/base.php'; require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/external/api/api.php'; require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/external/api/mobile.php'; externalApi_Mobile::addPushMsg($tar_id, 'message', array('from_user_id' => get_uid(false), 'text' => stripslashes($text))); } } } return array($alert, $error); }
/** * Сохранение комментария к статьям * * @param object $objResponse xajaxResponse * @param string $rec_id идентификатор записи * @param string $rec_type тип записи * @param array $aForm массив данных * @param string $sDrawFunc имя функции для выполнения после сохранения */ function _admEditArtComSaveForm(&$objResponse, $rec_id = '', $rec_type = '', $aForm = array(), $sDrawFunc = '') { require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/messages.php'; require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/user_content.php'; require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/attachedfiles.php'; require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/comments/CommentsArticles.php'; $oComments = new CommentsArticles(); $attachedfiles = new attachedfiles($aForm['attachedfiles_session']); $attachedfiles_files = $attachedfiles->getFiles(array(1, 3, 4)); $oComments->addAttachedFiles($attachedfiles_files, $rec_id, $aForm['user_login']); $attachedfiles->clear(); $sReason = _parseReason($aForm['user_id'], $aForm['adm_edit_text']); messages::artComModifiedNotification($rec_id, $aForm['user_login'], $aForm['user_uname'], $aForm['user_usurname'], $sReason, $aForm['resource']); $content_id = user_content::MODER_ART_COM; _admEditAfterAll($objResponse, $content_id, $rec_id, $rec_type, $sDrawFunc, $aForm); }
$attachedfiles = new attachedfiles($attachedfiles_session); $asid = $attachedfiles_session; } $attachedfiles_info = $attachedfiles->calcFiles(); if ($attachedfiles_session) { $countfiles = 0; } if ($msg === '' && $question === '' && empty($alert[5]) && !($countfiles || $attachedfiles_info['count']) && $yt_link === '') { $error_flag = 1; $alert[2] = 'Ошибка. Сообщение не должно быть пустым!'; } elseif (!$error && !$error_flag && ($msg !== '' || $attach['name'] || $attach_have || $attach_delete || $question || $yt_link || $attachedfiles_info['count'])) { $blog_obj->Edit($_SESSION['uid'], $thread, $msg, $msg_name, $files, getRemoteIP(), $err, $mod, NULL, $gr, $t, $attach_delete, $olduserlogin, $yt_link, $close_comments, $is_private, $ontop, null, $question, $answers, $answers_exists, $multiple); //$nStopWordsCnt = $stop_words->calculate( $msg, $msg_name, $question, $answers, $answers_exists ); $attachedfiles_files = $attachedfiles->getFiles(array(1, 3, 4)); $blog_obj->addAttachedFiles($attachedfiles_files, $thread, $olduserlogin, $draft_id ? true : false); $attachedfiles->clear(); //$blog_obj->insertIntoModeration( $thread, $nStopWordsCnt ); // больше не модерируем if ($err) { $alert = $alert + $err; } if ($draft_id && !($alert || $error || $error_flag)) { require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/drafts.php'; drafts::DeleteDraft($draft_id, get_uid(false), 3, true); } } if ($site == 'journal') { unset($_SESSION['user.journal.change.result']); if ($alert || $error || $error_flag) { $question = str_replace(array('"', "'", '\\', '<', '>'), array('"', ''', '\', '<', '>'), stripslashes($_POST['question'])); $answers = array(); $answers_exists = array();
/** * Создает новую сделку по данным пользовательског запроса. * * @param array $request данные запроса (гет, пост). * @param attachedfiles $files * * @return bool успешно? */ public function _new_create($request, attachedfiles $files) { if ($request['scheme_type'] == sbr::SCHEME_PDRD2) { return false; } $attached = $files->getFiles(array(1, 3), true); foreach ($request['stages'] as $num => $stage) { if (isset($stage['attaches']) && is_array($stage['attaches'])) { foreach ($stage['attaches'] as $anum => $att_id) { if (!isset($attached[$att_id])) { continue; } // $attached[$att_id]['id'] = md5($attached[$att_id]['id']); $request['stages'][$num]['attached'][$anum] = $attached[$att_id]; } } } if (!$this->_new_initFromRequest($request)) { return false; } if (!$this->_openXact(true)) { return false; } $sql_data = $this->_preSql(); $sql = "\n INSERT INTO sbr(emp_id, frl_id, project_id, name, cost_sys, is_draft, scheme_type)\n VALUES ({$this->uid}, {$sql_data['frl_id']}, " . ($sql_data['is_draft'] === 't' ? 'NULL' : $sql_data['project_id']) . ", '{$sql_data['name']}', {$sql_data['cost_sys']}, '{$sql_data['is_draft']}', {$sql_data['scheme_type']} )\n RETURNING id;\n "; if (!($res = pg_query(self::connect(false), $sql))) { $this->_abortXact(); return false; } $this->data['id'] = pg_fetch_result($res, 0, 0); foreach ($this->stages as $num => $stage) { if (!$stage->_new_create()) { $this->_abortXact(); unset($this->data['id']); return false; } elseif ($num == 0) { $this->addRefTService($stage->id); } } if ($this->scheme_type == sbr::SCHEME_LC) { if ($doc_file = $this->generateAgreement($err)) { $doc = array('file_id' => $doc_file->id, 'status' => sbr::DOCS_STATUS_SIGN, 'access_role' => sbr::DOCS_ACCESS_ALL, 'owner_role' => 0, 'type' => sbr::DOCS_TYPE_OFFER, 'subtype' => 2); $this->addDocR($doc); } if (!$err) { if ($doc_file = $this->generateContract($err)) { $doc = array('file_id' => $doc_file->id, 'status' => sbr::DOCS_STATUS_SIGN, 'access_role' => sbr::DOCS_ACCESS_ALL, 'owner_role' => 0, 'type' => sbr::DOCS_TYPE_OFFER, 'subtype' => 1); $this->addDocR($doc); } } if ($err) { $this->_abortXact(); unset($this->data['id']); return false; } } // записываем профессию сделки $this->saveProfessions(); $this->_commitXact(); $files->clear(); return true; }
/** * @param $frm - данные запроса * @param $type - тип страницы, с которой была запрошена форма быстрого редактирования проекта * 1 - лента на главной, * 2 - редактируется конкурс, * 3 - страница проекта в профиле работодателя, * 4 - проект в списке в профиле работодателя * */ function quickprjedit_save_prj($frm, $type) { $objResponse = new xajaxResponse(); if (hasPermissions('projects')) { require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/projects.php'; $oprj = new new_projects(); $project = $oprj->getPrj($frm['id']); if ($project['id']) { $objResponse->script('popupQEditPrjHideErrors();'); $key = $frm['tmpid']; $tmpPrj = new tmp_project($key); $tmpPrj->init(2); $errors = array(); $frm['name'] = trim($frm['name']); $frm['descr'] = trim($frm['descr']); if ($frm['link'] == 'Адрес сайта') { $frm['link'] = ''; } $frm['link'] == trim($frm['link']); if (!empty($frm['link'])) { if (strpos($frm['link'], 'http://') === 0) { $protocol = 'http://'; } if (strpos($frm['link'], 'https://') === 0) { $protocol = 'https://'; } if ($protocol == '') { $protocol = 'http://'; } $frm['link'] = $protocol . ltrim($frm['link'], $protocol); if (!is_url($frm['link'])) { $errors[] = 'logourl'; } } if (empty($frm['name'])) { $errors[] = 'name'; } if (empty($frm['descr'])) { $errors[] = 'descr'; } if ($frm['pf_city']) { $frm['city'] = $frm['pf_city']; } if ($project['kind'] == 7) { if (!preg_match("/^([0-9]{1,2})\\-([0-9]{1,2})\\-([0-9]{4})\$/", $frm['end_date'], $o1) || !checkdate($o1[2], $o1[1], $o1[3])) { $errors[] = 'end_date'; } if (!preg_match("/^([0-9]{1,2})\\-([0-9]{1,2})\\-([0-9]{4})\$/", $frm['win_date'], $o2) || !checkdate($o2[2], $o2[1], $o2[3])) { $errors[] = 'win_date'; } if (!in_array('end_date', $errors) && mktime(0, 0, 0, $o1[2], $o1[1], $o1[3]) <= mktime(0, 0, 0)) { $errors[] = 'end_date_past'; } if (!in_array('end_date', $errors) && mktime(0, 0, 0, $o2[2], $o2[1], $o2[3]) <= mktime(0, 0, 0, $o1[2], $o1[1], $o1[3])) { $errors[] = 'win_date_past'; } } if (!count($errors)) { $c = $frm['categories']; $sc = $frm['subcategories']; foreach ($frm['categories'] as $sKey => $value) { if ($value == 0) { continue; } $check[] = $value . '_' . $sc[$sKey]; } $uniq = array_unique($check); foreach ($uniq as $val) { list($cat, $subcat) = explode('_', $val); $check_array[$cat][] = $subcat; } $categories = array(); foreach ($check_array as $k => $val) { if (count($val) > 1 && array_search(0, $val) !== false) { $categories[] = array('category_id' => $k, 'subcategory_id' => 0); unset($check_array[$k]); } else { foreach ($val as $m => $v) { $categories[] = array('category_id' => $k, 'subcategory_id' => $v); } } } $tmpPrj->setProjectField('name', change_q_x($frm['name']), true); $tmpPrj->setProjectField('descr', change_q_x($frm['descr'], false, true, '', false, false)); $tmpPrj->setProjectField('pro_only', $frm['pro_only'] == 1 ? 't' : 'f'); $tmpPrj->setProjectField('verify_only', $frm['verify_only'] == 1 ? 't' : 'f'); $tmpPrj->setProjectField('strong_top', (int) $frm['strong_top']); $tmpPrj->setProjectField('prefer_sbr', $frm['prefer_sbr'] == 1 ? 't' : 'f'); $tmpPrj->setProjectField('urgent', $frm['is_urgent'] == 1 ? 't' : 'f'); $tmpPrj->setProjectField('hide', $frm['is_hide'] == 1 ? 't' : 'f'); switch ($frm['kind']) { case 1: $tmpPrj->setProjectField('country', 0); $tmpPrj->setProjectField('city', 0); $tmpPrj->setProjectField('kind', $frm['kind']); break; case 4: $tmpPrj->setProjectField('country', $frm['country']); $tmpPrj->setProjectField('city', $frm['city']); $tmpPrj->setProjectField('kind', $frm['kind']); break; } if ($project['kind'] == 7) { $tmpPrj->setProjectField('end_date', $frm['end_date']); $tmpPrj->setProjectField('win_date', $frm['win_date']); $tmpPrj->clearWinners(); } $tmpPrj->setCategories($categories); $tmpPrj->setProjectField('link', $frm['link']); $tmpPrj->setProjectField('is_color', $frm['is_color'] == 1 ? 't' : 'f'); $tmpPrj->setProjectField('is_bold', $frm['is_bold'] == 1 ? 't' : 'f'); $tmpPrj->setAddedTopDays($frm['top_ok'] == 1 ? $frm['top_days'] : 0); if (!$project['folder_id']) { $tmpPrj->setProjectField('folder_id', 0); } require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/attachedfiles.php'; $attachedfiles = new attachedfiles($frm['attachedfiles_session']); $attachedfiles_files = $attachedfiles->getFiles(array(1, 3, 4)); $tmpPrj->addAttachedFiles($attachedfiles_files); $attachedfiles->clear(); $tmpPrj->saveProject(get_uid(false), $ttt); require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/project_exrates.php'; require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/stop_words.php'; $stop_words = new stop_words(hasPermissions('projects')); $objResponse->script('popupQEditPrjHide();'); switch ($type) { case 1: case 4: // Лента проектов global $session; require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/projects.php'; $prj_id = $project['id']; $obj_project = new new_projects(); $tproject = $obj_project->getProjects($num, -1, 1, false, null, false, true, $prj_id); $this_kind = $tproject[0]['kind']; $this_uid = get_uid(false); $this_pro_last = $_SESSION['pro_last']; $this_is_pro = payed::CheckPro($_SESSION['login']); $this_edit_mode = hasPermissions('projects'); if ($this_uid) { $this_user_role = $_SESSION['role']; } $this_project = $tproject[0]; $row = $this_project; if ($this_edit_mode || $this_project['kind'] == 2 || $this_project['user_id'] == $this_uid || $this_project['offer_id'] || $this_pro_last) { $this_show_data = 1; $row['show_data'] = 1; } else { $this_show_data = 0; $row['show_data'] = 0; } $descr = $row['descr']; $descr = preg_replace('/^ /', "", $descr); $descr = preg_replace("/(\n) /", "\$1", $descr); $descr = reformat(strip_tags(LenghtFormatEx($descr, 180), '<br />'), 50, 1, 0, 1); $descr = preg_replace("//", ' ', $descr); $row['descr'] = $descr; $row['t_is_payed'] = $this_project['payed'] && $this_project['kind'] != 2 && $this_project['kind'] != 7; $row['t_is_contest'] = $this_project['kind'] == 2 || $this_project['kind'] == 7; $row['t_pro_only'] = $this_project['pro_only'] == 't'; $row['t_verify_only'] = $this_project['verify_only'] == 't'; $row['t_hide'] = $this_project['hide'] == 't'; $row['t_urgent'] = $this_project['urgent'] == 't'; $row['t_prefer_sbr'] = $this_project['prefer_sbr'] == 't'; $row['priceby'] = $this_project['priceby']; $row['t_is_adm'] = hasPermissions('projects'); $row['t_is_ontop'] = strtotime($this_project['top_to']) >= time(); $row['unread'] = (int) $this_project['unread_p_msgs'] + (int) $this_project['unread_c_msgs'] + (int) $this_project['unread_c_prjs']; $row['t_is_proonly'] = $this_project['pro_only'] == 't' && !$_SESSION['pro_last'] && !$this_edit_mode && $this_uid != $this_project['user_id']; $attaches = projects::GetAllAttach($this_project['id']); $attaches = !$attaches ? array() : $attaches; foreach ($attaches as $k => $a) { $a['virus'] = is_null($a['virus']) ? $a['virus'] : bindec($a['virus']); $attaches[$k] = $a; } $row['attaches'] = $this_project['attaches'] = $attaches; $is_ajax = true; $can_change_prj = hasPermissions('projects'); $row['friendly_url'] = getFriendlyURL('project', $row['id']); ob_start(); if ($type == 1) { $project = projects::initData($row); require_once $_SERVER['DOCUMENT_ROOT'] . '/projects/tpl.lenta-item.php'; } else { require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/employer.php'; $user = new employer(); $user->GetUserByUID($this_project['user_id']); require_once $_SERVER['DOCUMENT_ROOT'] . '/projects/tpl.employer-project-item.php'; } $html_data = ob_get_contents(); ob_end_clean(); $objResponse->assign("project-item{$prj_id}", 'innerHTML', $html_data); if ($row['is_color'] == 't') { $objResponse->script("\$('project-item{$prj_id}').addClass('b-post_bg_fffded')"); } else { $objResponse->script("\$('project-item{$prj_id}').removeClass('b-post_bg_fffded')"); } //$objResponse->script('alert("Лента");'); //$objResponse->script('window.location.reload();'); break; case 2: // Конкурс //$objResponse->script('alert("Конкурс");'); $project_exRates = project_exrates::GetAll(); $translate_exRates = array(0 => 2, 1 => 3, 2 => 4, 3 => 1); global $session; require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/contest.php'; $prj_id = $project['id']; $obj_project = new projects(); $project = $obj_project->GetPrjCust($prj_id); if (hasPermissions('projects')) { $project_history = $obj_project->GetPrjHistory($prj_id); } $project_attach = $obj_project->GetAllAttach($prj_id); $contest = new contest($project['id'], $uid, is_emp(), $project['user_id'] == $uid, hasPermissions('projects'), is_pro()); $contest->GetOffers((string) $_GET['filter']); $project['contest_end'] = mktime() > strtotime($project['end_date']); $project['contest_win'] = mktime() > strtotime($project['win_date']); if (trim($project['contacts']) != '') { $contacts_employer = unserialize($project['contacts']); $empty_contacts_employer = 0; foreach ($contacts_employer as $name => $contact) { if (trim($contact['value']) == '') { $empty_contacts_employer++; } } $is_contacts_employer_empty = count($contacts_employer) == $empty_contacts_employer; } ob_start(); require_once $_SERVER['DOCUMENT_ROOT'] . '/projects/contest_item.php'; $html_data = ob_get_contents(); ob_end_clean(); $objResponse->assign("contest_info_{$prj_id}", 'innerHTML', $html_data); break; case 3: // Проект $project_exRates = project_exrates::GetAll(); $translate_exRates = array(0 => 2, 1 => 3, 2 => 4, 3 => 1); $prj_id = $project['id']; $obj_project = new projects(); $project = $obj_project->GetPrjCust($prj_id); if (trim($project['contacts']) != '') { $contacts_employer = unserialize($project['contacts']); $empty_contacts_employer = 0; foreach ($contacts_employer as $name => $contact) { if (trim($contact['value']) == '') { $empty_contacts_employer++; } } $is_contacts_employer_empty = count($contacts_employer) == $empty_contacts_employer; } $project_attach = $obj_project->GetAllAttach($prj_id); ob_start(); require_once $_SERVER['DOCUMENT_ROOT'] . '/projects/tpl.prj-main-info.php'; $html_data = ob_get_contents(); ob_end_clean(); $objResponse->assign("project_info_{$project['id']}", 'innerHTML', $html_data); break; default: $objResponse->script('window.location.reload();'); break; } } else { $tab1 = 0; $tab2 = 0; foreach ($errors as $error) { switch ($error) { case 'end_date': $objResponse->script('$("popup_qedit_prj_fld_err_txt_cal1").set("html", "Неправильная дата");'); $objResponse->script('popupQEditPrjShowError("cal1");'); break; case 'win_date': $objResponse->script('$("popup_qedit_prj_fld_err_txt_cal2").set("html", "Неправильная дата");'); $objResponse->script('popupQEditPrjShowError("cal2");'); break; case 'end_date_past': $objResponse->script('$("popup_qedit_prj_fld_err_txt_cal1").set("html", "Дата окончания конкурса не может находиться в прошлом");'); $objResponse->script('popupQEditPrjShowError("cal1");'); break; case 'win_date_past': $objResponse->script('$("popup_qedit_prj_fld_err_txt_cal2").set("html", "Дата определения победителя должна быть больше даты окончания конкурса");'); $objResponse->script('popupQEditPrjShowError("cal2");'); break; case 'logourl': $objResponse->script('$("popup_qedit_prj_fld_err_pay").setStyle("display","block");'); $objResponse->script('$("popup_qedit_prj_fld_err_pay_txt").set("html", "Ссылка для логотипа указана не верно");'); break; default: $objResponse->script('popupQEditPrjShowError("' . $error . '");'); break; } if (in_array($error, array('name', 'descr', 'location', 'end_date', 'win_date', 'end_date_past', 'win_date_past'))) { ++$tab1; } elseif (in_array($error, array('logourl'))) { ++$tab2; } } if ($tab1) { $objResponse->script('popupQEditPrjMenu(1)'); } elseif ($tab2) { $objResponse->script('popupQEditPrjMenu(2)'); } } } $objResponse->script('popupQEditIsProcess = false;'); } return $objResponse; }
/** * Обработка информации шага проекты. */ public function actionProjects() { $prj_id = $_SESSION['view_wizard_project']; if (!$prj_id) { require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/attachedfiles.php'; require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/project_exrates.php'; require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/professions.php'; require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/projects.php'; require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/country.php'; require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/city.php'; $prj_exrates = project_exrates::GetAll(); $categories = professions::GetAllGroupsLite(); $professions = professions::GetAllProfessions(); array_group($professions, 'groupid'); $professions[0] = array(); $addedPrc = is_pro() ? 0 : new_projects::PRICE_ADDED; $colorPrc = new_projects::PRICE_COLOR * ($addedPrc > 0 ? 1 : 0); $boldPrc = new_projects::PRICE_BOLD + $addedPrc; $logoPrc = new_projects::PRICE_LOGO + $addedPrc; $cTopPrice = new_projects::PRICE_CONTEST_TOP1DAY + $addedPrc; $pTopPrice = new_projects::PRICE_TOP1DAY + $addedPrc; $action = __paramInit('string', 'action', 'action', null); $attachedfiles_session = __paramInit('string', 'attachedfiles_session', 'attachedfiles_session', false); // проверяем есть ли уже созданый проект $projects = $this->getCreatedProjects(); $existPrjID = count($projects) > 0 ? $projects[0][id] : null; // выводим ранее сохраненный проект if ($action != 'create_project' && $existPrjID) { $data = $projects[0]; list($category, $subcategory) = explode('|', $data['categories']); $currency_name = $this->CURRENCY_TYPE[$data['currency']]; $priceby_name = $this->PRICEBY_TYPE[$data['priceby']]; $data['pro_only'] = $data['pro_only'] === 't'; $price = $data['payed']; $option = array(); $option['top'] = $data['top_count'] > 0; $option['top_count'] = $data['top_count']; $option['color'] = $data['is_color'] === 't'; $option['bold'] = $data['is_bold'] === 't'; $option['logo'] = $data['logo_id'] > 0; } elseif ($action == 'create_project') { // сохраняем новый проект или изменяем старый $in_office = __paramInit('int', null, 'in_office', 0); $type = __paramInit('string', null, 'kind'); if ($type == 'contest') { $data['kind'] = 7; $data['end_date'] = date('d-m-Y', strtotime(__paramInit('string', null, 'end_date_eng_format', 0))); $data['win_date'] = date('d-m-Y', strtotime(__paramInit('string', null, 'win_date_eng_format', 0))); } elseif ($in_office == 1) { $location = __paramInit('integer', null, 'location_column_id'); if ($location == 1) { $data['city'] = __paramInit('integer', null, 'location_db_id'); $data['country'] = country::getCountryByCityId($data['city']); } else { $data['country'] = __paramInit('integer', null, 'location_db_id'); } $data['kind'] = 4; } else { $data['kind'] = 1; } $data['name'] = __paramInit('string', null, 'name'); $data['descr'] = __paramInit('string', null, 'descr'); $category = __paramInit('int', null, 'r_category'); $subcategory = __paramInit('int', null, 'r_subcategory'); $agreement = __paramInit('int', null, 'agreement', 0); $data['pro_only'] = __paramInit('int', null, 'pro_only', 0) == 1 ? true : false; if ($agreement != 1) { $data['cost'] = __paramInit('int', null, 'cost', 0); $data['priceby'] = __paramInit('int', null, 'r_priceby', 0); $data['currency'] = __paramInit('int', null, 'r_currency', 0); $data['budget_type'] = __paramInit('int', null, 'budget_type', 0); } if (is_empty_html($data['descr'])) { $error['descr'] = 'Поле не заполнено'; } if (is_empty_html($data['name'])) { $error['name'] = 'Поле не заполнено'; } // проверяем длину необработанной строки, а иначе спецсимволы считаются как несколько символов if (strlen(stripslashes($_POST['name'])) > 60) { $error['name'] = 'Превышен лимит - 60 символов'; } if (!$category) { $error['category'] = 'Не выбран раздел'; } elseif ($subcategory) { $data['categories'] = "{$category}|{$subcategory}"; } else { $data['categories'] = $category; } if ($data['cost'] < 0) { $error['cost'] = 'Введите положительную сумму'; } if ($data['cost'] > 999999) { $error['cost'] = 'Слишком большая сумма'; } if ($data['cost'] > 0 && ($data['currency'] < 0 || $data['currency'] > 3)) { $error['currency'] = 'Валюта не определена'; } if ($data['cost'] > 0 && ($data['priceby'] < 1 || $data['priceby'] > 4)) { $error['priceby'] = 'Вид бюджета не определен'; } $descr_limit = projects::LIMIT_DESCR; if (strlen_real($data['descr']) > $descr_limit) { $error['descr'] = "Исчерпан лимит символов ({$descr_limit})"; } if ($data['kind'] == 7) { if (!preg_match("/^([0-9]{1,2})\\-([0-9]{1,2})\\-([0-9]{4})\$/", $data['end_date'], $o1) || !checkdate($o1[2], $o1[1], $o1[3])) { $error['end_date'] = 'Неправильная дата'; } if (!preg_match("/^([0-9]{1,2})\\-([0-9]{1,2})\\-([0-9]{4})\$/", $data['win_date'], $o2) || !checkdate($o2[2], $o2[1], $o2[3])) { $error['win_date'] = 'Неправильная дата'; } if (!$error['end_date'] && mktime(0, 0, 0, $o1[2], $o1[1], $o1[3]) <= mktime(0, 0, 0)) { $error['end_date'] = 'Дата окончания конкурса не может находиться в прошлом'; } if (!$error['win_date'] && mktime(0, 0, 0, $o2[2], $o2[1], $o2[3]) <= mktime(0, 0, 0, $o1[2], $o1[1], $o1[3])) { $error['win_date'] = 'Дата определения победителя должна быть больше даты окончания конкурса'; } } $option['top'] = __paramInit('int', null, 'option_top', 0); $option['top_count'] = __paramInit('int', null, 'option_top_count', 0); $option['color'] = __paramInit('int', null, 'option_color', 0); $option['bold'] = __paramInit('int', null, 'option_bold', 0); $option['logo'] = __paramInit('int', null, 'option_logo', 0); // логотип if ($option['logo'] == 1) { $data['logo_link'] = str_replace('http://', '', __paramInit('string', null, 'logo_link', null)); $data['logo_id'] = __paramInit('int', null, 'logo_id', null); // если выбрана опция "Логотип со ссылкой", то картинка должна быть обязательно if (!$data['logo_id']) { $error['logo_image'] = 'Отсутствует логотип'; } if ($data['logo_link'] === 'Адрес сайта') { $data['logo_link'] = ''; } if ($data['logo_link'] !== '' && !is_url($data['logo_link'])) { $error['logo_link'] = 'Не верно введен адрес'; } } else { $data['logo_id'] = null; } $price = 0; // закрепление на верху if ($option['top'] == 1 && $option['top_count'] > 0) { if ($option['top_count'] > 999) { $option['top_count'] = 999; } $price = (int) $option['top_count'] * ($data['kind'] == 7 ? $cTopPrice : $pTopPrice); $data['top_count'] = (int) $option['top_count']; $pay_option[] = array('wiz_uid' => $this->getWizardUserID(), 'op_code' => new_projects::OPCODE_PAYED, 'option' => self::PROJECT_OPTION_TOP, 'type' => $data['kind'] == 7 ? self::BILL_TYPE_CONTEST : self::BILL_TYPE_PROJECT, 'ammount' => $price); } else { $data['top_count'] = 0; } // выделение цветом if ($option['color'] == 1) { $price += (int) $colorPrc; $data['is_color'] = true; $pay_option[] = array('wiz_uid' => $this->getWizardUserID(), 'op_code' => new_projects::OPCODE_PAYED, 'option' => self::PROJECT_OPTION_COLOR, 'type' => $data['kind'] == 7 ? self::BILL_TYPE_CONTEST : self::BILL_TYPE_PROJECT, 'ammount' => $colorPrc); } else { $data['is_color'] = false; } // выделение жирным if ($option['bold'] == 1) { $price += (int) $boldPrc; $data['is_bold'] = true; $pay_option[] = array('wiz_uid' => $this->getWizardUserID(), 'op_code' => new_projects::OPCODE_PAYED, 'option' => self::PROJECT_OPTION_BOLD, 'type' => $data['kind'] == 7 ? self::BILL_TYPE_CONTEST : self::BILL_TYPE_PROJECT, 'ammount' => $boldPrc); } else { $data['is_bold'] = false; } if ($option['logo'] == 1) { $price += (int) $logoPrc; $pay_option[] = array('wiz_uid' => $this->getWizardUserID(), 'op_code' => new_projects::OPCODE_PAYED, 'option' => self::PROJECT_OPTION_LOGO, 'type' => $data['kind'] == 7 ? self::BILL_TYPE_CONTEST : self::BILL_TYPE_PROJECT, 'ammount' => $logoPrc); } if ($price > 0) { $data['payed'] = (int) $price; } if (!$error) { $data['wiz_uid'] = $this->getWizardUserID(); // если проект уже есть if ($existPrjID) { // то просто обновляем его $prj_id = $this->updateProject($data, $existPrjID); // и очищаем все платные опции для этого проекта wizard_billing::clearPayedOptions($prj_id); } else { $prj_id = $this->createProject($data); } if ($prj_id && $_POST['attachedfiles_session']) { $attachedfiles = new attachedfiles($_POST['attachedfiles_session']); $files = $attachedfiles->getFiles(array(1, 2, 3, 4)); $this->parent->addAttachedFiles($files, $prj_id); $attachedfiles->clear(); } if ($prj_id && $data['kind'] == 7) { $insert = array('wiz_uid' => $data['wiz_uid'], 'op_code' => new_projects::OPCODE_KON_NOPRO, 'type' => self::BILL_TYPE_CONTEST, 'ammount' => new_projects::getKonkursPrice(), 'parent' => $prj_id); wizard_billing::addPaidOption($insert); } if ($price > 0 && $prj_id) { foreach ($pay_option as $k => $opt) { $opt['parent'] = $prj_id; wizard_billing::addPaidOption($opt); } } if ($prj_id) { $_SESSION['view_wizard_project'] = $prj_id; header('Location: /wizard/registration/'); exit; } else { $error['project'] = 'Ошибка записи проекта'; } } $currency_name = __paramInit('string', null, 'currency'); $priceby_name = __paramInit('string', null, 'priceby'); } // Генерируем данные для вывода ошибок и заполнения полей $loc[] = country::GetCountryName($data['country']); if ($data['city']) { $loc[] = city::GetCityName($data['city']); } $location_name = implode(': ', $loc); $cat[] = professions::GetGroupName($category); if ($subcategory) { $cat[] = professions::GetProfName($subcategory); } $category_name = implode(': ', $cat); if ($data['logo_id']) { $file = new CFile($data['logo_id']); $logo_path = WDCPREFIX . '/' . $file->path . $file->name; } include $_SERVER['DOCUMENT_ROOT'] . '/wizard/registration/steps/tpl.step.project.php'; } else { $project = $this->getProjectById($prj_id); $attached = $this->getProjectAttach($prj_id); include $_SERVER['DOCUMENT_ROOT'] . '/wizard/registration/steps/tpl.step.project.view.php'; } }
/** * Изменение документа * * @param integer $id ID документа * @param array $data Данные документа */ function updateDocument($id, $data) { global $DB; if (!$data['letters_doc_frm_user_3_db_id'] || $data['letters_doc_frm_user_3_db_id'] == 'null') { $data['letters_doc_frm_user_3_db_id'] = null; $data['letters_doc_frm_user3_status_data'] = null; $data['letters_doc_frm_user3_status_date_data'] = null; } if (!$data['letters_doc_frm_user3_status_date_data']) { $data['letters_doc_frm_user3_status_date_data'] = null; } if (!$data['letters_doc_frm_user2_status_date_data']) { $data['letters_doc_frm_user2_status_date_data'] = null; } if (!$data['letters_doc_frm_user1_status_date_data']) { $data['letters_doc_frm_user1_status_date_data'] = null; } if (!$data['letters_doc_frm_user3_status_data']) { $data['letters_doc_frm_user3_status_data'] = null; } if (!$data['letters_doc_frm_user2_status_data']) { $data['letters_doc_frm_user2_status_data'] = null; } if (!$data['letters_doc_frm_user1_status_data']) { $data['letters_doc_frm_user1_status_data'] = null; } if (!$data['letters_doc_frm_parent_db_id'] || $data['letters_doc_frm_parent_db_id'] == 'null') { $data['letters_doc_frm_parent_db_id'] = null; } if (!$data['letters_doc_frm_group'] || $data['letters_doc_frm_group'] == 'null') { $data['letters_doc_frm_group'] = null; } if (!$data['letters_doc_frm_group_db_id'] || $data['letters_doc_frm_group_db_id'] == 'null') { $data['letters_doc_frm_group_db_id'] = null; } if (!$data['letters_doc_frm_group_db_id'] && !empty($data['letters_doc_frm_group'])) { $data['letters_doc_frm_group_db_id'] = letters::checkCreateGroup($data['letters_doc_frm_group']); } if ($data['letters_doc_frm_user_1_section'] == '1') { $data['letters_doc_frm_user_1_section'] = true; } else { $data['letters_doc_frm_user_1_section'] = false; } if ($data['letters_doc_frm_user_2_section'] == '1') { $data['letters_doc_frm_user_2_section'] = true; } else { $data['letters_doc_frm_user_2_section'] = false; } if ($data['letters_doc_frm_user_3_section'] == '1') { $data['letters_doc_frm_user_3_section'] = true; } else { $data['letters_doc_frm_user_3_section'] = false; } if ($data['letters_doc_frm_withoutourdoc'] == '1') { $data['letters_doc_frm_withoutourdoc'] = true; } else { $data['letters_doc_frm_withoutourdoc'] = false; } $doc = self::getDocument($id); $doc_data['title'] = $data['letters_doc_frm_title']; $doc_data['user_1'] = $data['letters_doc_frm_user_1_db_id']; $doc_data['user_2'] = $data['letters_doc_frm_user_2_db_id']; $doc_data['user_3'] = $data['letters_doc_frm_user_3_db_id']; $doc_data['group_id'] = $data['letters_doc_frm_group_db_id']; $doc_data['parent'] = $data['letters_doc_frm_parent_db_id']; $doc_data['user_status_1'] = $data['letters_doc_frm_user1_status_data']; $doc_data['user_status_2'] = $data['letters_doc_frm_user2_status_data']; $doc_data['user_status_3'] = $data['letters_doc_frm_user3_status_data']; $doc_data['user_status_date_1'] = $data['letters_doc_frm_user1_status_date_data']; $doc_data['user_status_date_2'] = $data['letters_doc_frm_user2_status_date_data']; $doc_data['user_status_date_3'] = $data['letters_doc_frm_user3_status_date_data']; $doc_data['is_user_1_company'] = $data['letters_doc_frm_user_1_section'] ? 't' : 'f'; $doc_data['is_user_2_company'] = $data['letters_doc_frm_user_2_section'] ? 't' : 'f'; $doc_data['is_user_3_company'] = $data['letters_doc_frm_user_3_section'] ? 't' : 'f'; $doc_data['withoutourdoc'] = $data['withoutourdoc'] ? 't' : 'f'; if (isset($data['letters_doc_frm_comment']) && $data['letters_doc_frm_comment']) { $doc_data['comment'] = $data['letters_doc_frm_comment']; } else { $data['letters_doc_frm_comment'] = $doc['comment']; } if ($doc_data['user_status_1'] != $doc['user_status_1'] || $doc_data['user_status_2'] != $doc['user_status_2'] || $doc_data['user_status_3'] != $doc['user_status_3']) { letters::updateDateStatusChange($id); } letters::saveHistory($id, $doc_data); $sql = "UPDATE letters SET\n date_add = " . ($data['letters_doc_frm_dateadd_eng_format'] ? "'{$data['letters_doc_frm_dateadd_eng_format']}'" : "NOW()") . ",\n title = ?,\n user_1 = ?,\n user_2 = ?,\n user_3 = ?,\n group_id = ?,\n parent = ?,\n user_status_1 = ?, \n user_status_2 = ?, \n user_status_3 = ?, \n user_status_date_1 = ?, \n user_status_date_2 = ?, \n user_status_date_3 = ?,\n is_user_1_company = ?, \n is_user_2_company = ?, \n is_user_3_company = ?, \n withoutourdoc = ?,\n comment = ?\n WHERE id = ?i;"; $DB->query($sql, $data['letters_doc_frm_title'], $data['letters_doc_frm_user_1_db_id'], $data['letters_doc_frm_user_2_db_id'], $data['letters_doc_frm_user_3_db_id'], $data['letters_doc_frm_group_db_id'], $data['letters_doc_frm_parent_db_id'], $data['letters_doc_frm_user1_status_data'], $data['letters_doc_frm_user2_status_data'], $data['letters_doc_frm_user3_status_data'], $data['letters_doc_frm_user1_status_date_data'], $data['letters_doc_frm_user2_status_date_data'], $data['letters_doc_frm_user3_status_date_data'], $data['letters_doc_frm_user_1_section'], $data['letters_doc_frm_user_2_section'], $data['letters_doc_frm_user_3_section'], $data['letters_doc_frm_withoutourdoc'], $data['letters_doc_frm_comment'], $id); $sql = "UPDATE letters SET is_out=false WHERE (user_status_1 IS DISTINCT FROM 1 AND user_status_2 IS DISTINCT FROM 1 AND user_status_3 IS DISTINCT FROM 1) AND id=?i"; $DB->query($sql, $id); require_once $_SERVER['DOCUMENT_ROOT'] . "/classes/attachedfiles.php"; require_once $_SERVER['DOCUMENT_ROOT'] . "/classes/CFile.php"; $attachedfiles = new attachedfiles($data['attachedfiles_session']); $attachedfiles_files = $attachedfiles->getFiles(); if ($attachedfiles_files) { foreach ($attachedfiles_files as $attachedfiles_file) { $cFile = new CFile(); $cFile->table = 'file'; $cFile->GetInfoById($attachedfiles_file['id']); if ($cFile->id != $doc['file_id']) { $ext = $cFile->getext(); $tmp_dir = "letters/"; $tmp_name = $cFile->secure_tmpname($tmp_dir, '.' . $ext); $tmp_name = substr_replace($tmp_name, "", 0, strlen($tmp_dir)); $cFile->_remoteCopy($tmp_dir . $tmp_name, true); $sql = "UPDATE letters SET file_id = ?i WHERE id = ?i"; $DB->query($sql, $cFile->id, intval($id)); $cFile->delete($doc['file_id']); } } } $attachedfiles->clear(); return $id; }