/** * @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; }