コード例 #1
0
/**
 * Сохранение проектов и конкурсов
 * 
 * @param object $objResponse xajaxResponse
 * @param string $rec_id идентификатор записи
 * @param string $rec_type тип записи
 * @param array $aForm массив данных
 * @param string $sDrawFunc имя функции для выполнения после сохранения
 */
function _admEditProjectsSaveForm(&$objResponse, $rec_id = '', $rec_type = '', $aForm = array(), $sDrawFunc = '')
{
    require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/projects.php';
    require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/professions.php';
    require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/user_content.php';
    require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/attachedfiles.php';
    $alert = array();
    $tmpPrj = new tmp_project($aForm['temp_key']);
    $prj = $tmpPrj->init(2);
    $kind = isset($aForm['kind']) ? intvalPgSql($aForm['kind']) : $prj['kind'];
    $sLink = change_q_x($aForm['link'], false, true, null, false, false);
    if (!empty($sLink)) {
        if (!preg_match('/http:\\/\\//', $sLink)) {
            $sLink = 'http://' . $sLink;
        }
    }
    $tmpPrj->setProjectField('kind', $kind);
    $tmpPrj->setProjectField('descr', antispam(change_q_x($aForm['descr'], FALSE, TRUE, "", false, false)));
    $tmpPrj->setProjectField('name', substr(antispam(change_q_x($aForm['name'], TRUE)), 0, 512));
    setlocale(LC_ALL, 'en_US.UTF-8');
    $tmpPrj->setProjectField('cost', isset($aForm['cost']) ? floatval($aForm['cost']) : 0);
    $tmpPrj->setProjectField('currency', isset($aForm['currency']) ? intvalPgSql($aForm['currency']) : 0);
    $tmpPrj->setProjectField('folder_id', isset($aForm['folder_id']) ? intvalPgSql($aForm['folder_id']) : 0);
    $tmpPrj->setProjectField('budget_type', isset($aForm['budget_type']) ? intvalPgSql($aForm['budget_type']) : 0);
    $tmpPrj->setProjectField('priceby', isset($aForm['priceby']) ? intvalPgSql($aForm['priceby']) : 0);
    $tmpPrj->setProjectField('agreement', isset($aForm['agreement']) ? intvalPgSql($aForm['agreement']) : 0);
    $tmpPrj->setProjectField('country', isset($aForm['country']) ? intvalPgSql($aForm['country']) : 0);
    $tmpPrj->setProjectField('city', isset($aForm['pf_city']) ? intvalPgSql($aForm['pf_city']) : 0);
    $tmpPrj->setProjectField('pro_only', isset($aForm['pro_only']) ? 't' : 'f');
    $tmpPrj->setProjectField('is_color', isset($aForm['is_color']) ? 't' : 'f');
    $tmpPrj->setProjectField('is_bold', isset($aForm['is_bold']) ? 't' : 'f');
    $tmpPrj->setProjectField('link', $sLink);
    if ($kind == 7) {
        $tmpPrj->setProjectField('end_date', change_q_x($aForm['end_date'], TRUE));
        $tmpPrj->setProjectField('win_date', change_q_x($aForm['win_date'], TRUE));
    }
    // разделы
    $c = $aForm['categories'];
    $sc = $aForm['subcategories'];
    if (empty($c) || sizeof($c) == 1 && $c[0] == 0) {
        $alert[3] = 'Не выбран раздел';
    } else {
        $cats = array();
        foreach ($c 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;
        }
        foreach ($check_array as $k => $val) {
            if (count($val) > 1 && array_search(0, $val) !== false) {
                $cats[] = array('category_id' => $k, 'subcategory_id' => 0);
                unset($check_array[$k]);
            } else {
                foreach ($val as $m => $v) {
                    $cats[] = array('category_id' => $k, 'subcategory_id' => $v);
                }
            }
        }
        $tmpPrj->setCategories($cats);
    }
    $prj = $tmpPrj->getProject();
    $descr_limit = 5000;
    if ($prj['cost'] < 0) {
        $alert[7] = 'Введите положительную сумму';
    }
    if ($prj['cost'] > 999999) {
        $alert[7] = 'Слишком большая сумма';
    }
    if ($prj['cost'] > 0 && ($prj['currency'] < 0 || $prj['currency'] > 3)) {
        $alert[7] = 'Валюта не определена';
    }
    if (is_empty_html($prj['name'])) {
        $alert[1] = 'Поле не заполнено';
    }
    if (is_empty_html($prj['descr'])) {
        $alert[2] = 'Поле не заполнено';
    }
    if (strlen_real($prj['descr']) > $descr_limit) {
        $alert[2] = "Исчерпан лимит символов ({$descr_limit})";
    }
    if ($prj['kind'] == 7) {
        if (!preg_match("/^([0-9]{1,2})\\-([0-9]{1,2})\\-([0-9]{4})\$/", $prj['end_date'], $o1) || !checkdate($o1[2], $o1[1], $o1[3])) {
            $alert[5] = 'Неправильная дата';
        }
        if (!preg_match("/^([0-9]{1,2})\\-([0-9]{1,2})\\-([0-9]{4})\$/", $prj['win_date'], $o2) || !checkdate($o2[2], $o2[1], $o2[3])) {
            $alert[6] = 'Неправильная дата';
        }
        if (!$alert[5] && mktime(0, 0, 0, $o1[2], $o1[1], $o1[3]) <= mktime(0, 0, 0)) {
            $alert[5] = 'Дата окончания конкурса не может находиться  в прошлом';
        }
        if (!$alert[6] && mktime(0, 0, 0, $o2[2], $o2[1], $o2[3]) <= mktime(0, 0, 0, $o1[2], $o1[1], $o1[3])) {
            $alert[6] = 'Дата определения победителя должна быть больше даты окончания конкурса';
        }
    }
    /*elseif ( $prj['kind'] == 4 && ($prj['country'] == 0 || $prj['city'] == 0) ) {
          $alert[4] = 'Укажите местонахождение';
      }*/
    if (isset($aForm['top_ok'])) {
        $nDays = intval($aForm['top_days']);
        if (ctype_digit($aForm['top_days']) && $nDays > 0) {
            $tmpPrj->setAddedTopDays($nDays);
        } else {
            $alert[8] = 'Укажите корректное количество дней нверху';
        }
    } else {
        $tmpPrj->setAddedTopDays(0);
    }
    if (!isset($alert[8]) && isset($aForm['logo_ok'])) {
        if (empty($aForm['logo_id'])) {
            $alert[8] = 'Необходимо выбрать файл';
        }
    }
    if (isset($aForm['del_logo'])) {
        $tmpPrj->delLogo();
    }
    if (!$alert) {
        require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/messages.php';
        $attachedfiles = new attachedfiles($aForm['attachedfiles_session']);
        $attachedfiles_files = $attachedfiles->getFiles(array(1, 3, 4));
        $tmpPrj->addAttachedFiles($attachedfiles_files);
        $attachedfiles->clear();
        $sError = $tmpPrj->saveProject($prj['user_id'], $prj);
        if (!$sError) {
            if ($prj['agreement'] == 1 || $prj['cost'] == 0) {
                projects::updateBudget($rec_id, 0, 0, 0, true);
            } else {
                projects::updateBudget($rec_id, $prj['cost'], $prj['currency'], $prj['priceby'], false);
            }
            $sReason = _parseReason($aForm['user_id'], $aForm['adm_edit_text']);
            messages::projectsModifiedNotification($rec_id, $rec_type, $aForm['user_login'], $aForm['user_uname'], $aForm['user_usurname'], $sReason);
            $content_id = user_content::MODER_PROJECTS;
            _admEditAfterAll($objResponse, $content_id, $rec_id, $rec_type, $sDrawFunc, $aForm);
        } else {
            $objResponse->alert($sError);
            $sParent = $sDrawFunc == 'stream0' || $sDrawFunc == 'stream1' || $sDrawFunc == 'stream2' ? 'parent.' : '';
            $objResponse->script("{$sParent}adm_edit_content.disabled = false; {$sParent}adm_edit_content.button();");
        }
    } else {
        _setErrors($objResponse, $alert, array(1 => 'name', 2 => 'descr', 3 => 'categories', 4 => 'country', 5 => 'end_date', 6 => 'win_date', 7 => 'cost', 8 => 'paid'), $sDrawFunc);
    }
}
コード例 #2
0
function quickprjedit_save_budget($prj_id, $frm, $type, $page_type)
{
    require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/projects.php';
    $objResponse = new xajaxResponse();
    $budget = null;
    if (hasPermissions('projects')) {
        if ($frm['agreement'] == 1 || $frm['cost'] == 0) {
            $budget = projects::updateBudget($prj_id, 0, 0, 0, true);
            $str_budget_cost = 'По договоренности';
            $agreement = true;
            $str_budget_lnk = "popupShowChangeBudget({$prj_id}, '', 0, 1, true, {$prj_id}, " . ($type == 1 ? 1 : 2) . ', ' . ($page_type ? $page_type : 0) . '); return false;';
            $budget_block = '<table cellspacing="0" cellpadding="0">
                                <tr>
                                    <td>
                                        <div class="form">
                                        <b class="b1"></b>
                                        <b class="b2"></b>
                                            <div class="form-in">
                                            <a href="#" id="prj_budget_lnk_' . $prj_id . '" onClick="popupShowChangeBudget(' . $prj_id . ', \'\', 0, 1, true, ' . $prj_id . ', ' . ($type == 1 ? 1 : 2) . ', ' . ($page_type ? $page_type : 0) . '); return false;">Бюджет по договоренности</a>
                                            </div>
                                        <b class="b2"></b>
                                        <b class="b1"></b>
                                        </div>
                                    </td>
                                </tr>
                             </table>';
            $budget_block_class = 'prj_cost prj-dogovor';
        } else {
            if ($frm['cost'] > 0) {
                $budget = projects::updateBudget($prj_id, $frm['cost'], $frm['currency'], $frm['costby'], false);
                $str_budget_cost = CurToChar($budget['cost'], $budget['currency']);
                $agreement = false;
                $str_budget_lnk = "popupShowChangeBudget({$prj_id}, '{$budget['cost']}', '{$budget['currency']}', '{$budget['costby']}', false, {$prj_id}, " . ($type == 1 ? 1 : 2) . ', ' . ($page_type ? $page_type : 0) . '); return false;';
                $budget_block_class = 'prj_cost';
                $budget_block = '<div class="budget-block">';
                switch ($budget['budget_type']) {
                    default:
                        $budget_price_str = '';
                        $budget_price_class = 'fl-form-grey';
                        break;
                }
                if ($budget['cost'] == '' || $budget['cost'] == 0) {
                    $budget_price_str = '';
                    $budget_price_class = 'fl-form-grey';
                }
                if ($budget_price_str != '') {
                    $budget_block .= '
                         <div class="fl-form fl-form-tr budget-type">
                             ' . $budget_price_str . '
                             <span class="cc cc-lt"></span>
                             <span class="cc cc-rt"></span>
                             <span class="cc cc-lb"></span>
                             <span class="cc cc-rb"></span>
                             <span class="budget-type-lug"></span>
                         </div>';
                }
                $budget_block .= '<div class="fl-form ' . $budget_price_class . ' color-budget">';
                switch ($budget['costby']) {
                    case '1':
                        $priceby_str = '/час';
                        break;
                    case '2':
                        $priceby_str = '/день';
                        break;
                    case '3':
                        $priceby_str = '/месяц';
                        break;
                    case '4':
                        $priceby_str = '/проект';
                        break;
                    default:
                        $priceby_str = '';
                        break;
                }
                if ($budget['cost'] == '' || $budget['cost'] == 0) {
                    $priceby_str = '';
                }
                $budget_block .= '<strong>
                                <a href="#" id="prj_budget_lnk_' . $prj_id . '">Бюджет: ' . CurToChar($budget['cost'], $budget['currency']) . $priceby_str . '</a>
                             </strong>';
                if ($budget['cost'] > 0) {
                    $project_exRates = project_exrates::GetAll();
                    $exch = array(1 => 'FM', 'USD', 'Euro', 'Руб');
                    $translate_exRates = array(0 => 2, 1 => 3, 2 => 4, 3 => 1);
                    $price_other_cur = '';
                    if ($budget['currency'] != 0) {
                        $price_other_cur .= CurToChar(preg_replace('/.00$/', '', sprintf('%.2f', round($budget['cost'] * $project_exRates[trim($translate_exRates[$budget['currency']]) . '2'], 2))), 0) . 'AA';
                    }
                    if ($budget['currency'] != 1) {
                        $price_other_cur .= CurToChar(preg_replace('/.00$/', '', sprintf('%.2f', round($budget['cost'] * $project_exRates[trim($translate_exRates[$budget['currency']]) . '3'], 2))), 1) . 'AA';
                    }
                    if ($budget['currency'] != 2) {
                        $price_other_cur .= CurToChar(preg_replace('/.00$/', '', sprintf('%.2f', round($budget['cost'] * $project_exRates[trim($translate_exRates[$budget['currency']]) . '4'], 2))), 2) . 'AA';
                    }
                    if ($budget['currency'] != 3) {
                        $price_other_cur .= CurToChar(preg_replace('/.00$/', '', sprintf('%.2f', round($budget['cost'] * $project_exRates[trim($translate_exRates[$budget['currency']]) . '1'], 2))), 3) . 'AA';
                    }
                    $price_other_cur = preg_replace('/AA$/', '', $price_other_cur);
                    $price_other_cur = preg_replace('/AA/', '&nbsp;—&nbsp;', $price_other_cur);
                    $budget_block .= '<em>' . $price_other_cur . '</em>';
                }
                $budget_block .= '
                             <span class="cc cc-lt"></span>
                             <span class="cc cc-rt"></span>
                             <span class="cc cc-lb"></span>
                             <span class="cc cc-rb"></span>
                         </div>
                     </div>';
            }
        }
        switch ($budget['costby']) {
            case '1':
                $costby_str = '/час';
                break;
            case '2':
                $costby_str = '/день';
                break;
            case '3':
                $costby_str = '/месяц';
                break;
            case '4':
                $costby_str = '/проект';
                break;
            default:
                $costby_str = '';
                break;
        }
        $str_budget_cost = $str_budget_cost . $costby_str;
    }
    if ($budget) {
        switch ($type) {
            case 1:
                // Лента
                $objResponse->assign("prj_budget_lnk_{$prj_id}", 'innerHTML', $str_budget_cost);
                if ($agreement) {
                    $objResponse->script('$("prj_budget_lnk_' . $prj_id . '").getParent().removeClass("b-post__price_bold").removeClass("b-post__price_fontsize_15").addClass("bujet-dogovor");');
                } else {
                    if ($page_type != 2) {
                        $objResponse->script('$("prj_budget_lnk_' . $prj_id . '").getParent().addClass("b-post__price_bold").removeClass("b-post__price_fontsize_13").addClass("b-post__price_fontsize_15");');
                    } else {
                        $objResponse->script('$("prj_budget_lnk_' . $prj_id . '").getParent().removeClass("b-post__price_bold").removeClass("b-post__price_fontsize_13").removeClass("bujet-dogovor");');
                    }
                }
                $objResponse->script("\$('prj_budget_lnk_{$prj_id}').addEvent('click', function() { {$str_budget_lnk} });");
                break;
            case 2:
                // Проект
                $objResponse->assign('budget_block', 'innerHTML', $budget_block);
                $objResponse->script("\$('budget_block').set('class', '{$budget_block_class}');");
                $objResponse->script("\$('prj_budget_lnk_{$prj_id}').addEvent('click', function() { {$str_budget_lnk} });");
                break;
        }
    }
    return $objResponse;
}