/**
* Добавляет жалобу на проект.
*
* @param    integer     $project_id     ID проекта
* @param    integer     $user_id        ID пользователя
* @param    integer     $type           тип жалобы
* @param    string      $msg            текст жалобы
* @param    string      $files          имена загруженных скриншотов
*
* @return                               xajax responce
*/
function SendComplain($project_id, $type, $msg, $files)
{
    global $session;
    session_start();
    require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/uploader/uploader.php';
    require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/projects_complains.php';
    require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/userecho.php';
    $objResponse = new xajaxResponse();
    $project_id = (int) $project_id;
    $user_id = get_uid(false);
    $type = (int) $type;
    $msg = __paramValue('htmltext', $msg);
    $error = false;
    $project = new projects();
    $prj = $project->GetPrj(0, $project_id, 1);
    $file_list = array();
    if ($files != '') {
        $files = uploader::sgetFiles($files);
        if (!empty($files)) {
            $emp = new users();
            $emp->GetUser($emp->GetField($prj['user_id'], $ee, 'login'));
            $dir = 'users/' . substr($emp->login, 0, 2) . '/' . $emp->login . '/upload/';
            foreach ($files as $file) {
                $copy = uploader::remoteCopy($file['id'], 'file_projects', $dir);
                $rfiles[] = $copy->name;
                $file_list[] = array('name' => $copy->original_name, 'link' => WDCPREFIX . '/' . $copy->path . $copy->name);
            }
            $files = implode(',', $rfiles);
        } else {
            $files = '';
        }
    }
    if (!$files) {
        $files = '';
    }
    if (projects::IsHaveComplainType($project_id, $user_id, $type)) {
        // Уже жаловался
        return $objResponse;
    }
    $projects_complains = new projects_complains();
    $type_name = $projects_complains->GetComplainType($type);
    $project_url = getAbsUrl(getFriendlyURL('project', $project_id));
    $is_moder = $projects_complains->isComplainTypeModer($type);
    if ($is_moder) {
        $userEcho = new UserEcho();
        $topic_message = $userEcho->constructMessage($project_url, $prj['name'], $msg, $file_list);
        $topicUrl = $userEcho->newTopicComplain($type_name, $topic_message, $file_list);
        if ($topicUrl) {
            messages::sendProjectComplain($user_id, $project_url, $prj['name'], $msg, $topicUrl);
        } else {
            $error = true;
        }
    }
    if (!$error) {
        $error = projects::AddComplain($project_id, $user_id, $type, $msg, $files, $is_moder && $topicUrl);
    }
    if ($error) {
        $objResponse->script("\$('abuse_project_popup').toggleClass('b-shadow_hide');");
        if ($is_moder) {
            $objResponse->script("\$('abuse-cause-error').removeClass('b-layout__txt_hide'); abuseResetSelection();");
        } else {
            $objResponse->script("\$\$('.abuse-btn-send').removeClass('b-button_rectangle_color_disable')");
        }
    } else {
        $upl = array('umask' => uploader::umask('prj_abuse'), 'validation' => array('allowedExtensions' => array('jpg', 'gif', 'png', 'jpeg'), 'restrictedExtensions' => array()), 'text' => array('uploadButton' => iconv('cp1251', 'utf8', 'Прикрепить файлы')));
        $objResponse->script("\n            \$('abuse{$type}').addClass('abuse-checked');\n            \$('abuse{$type}').getChildren().each(function(el) { \$(el).addClass('abuse-checked'); });\n        ");
        $objResponse->script("uploader.create('abuse_uploader', " . json_encode($upl) . ');');
        $objResponse->script("\$('prj_abuse_msg').set('value', '')");
        $objResponse->script("\$\$('.abuse-btn-send').removeClass('b-button_disabled')");
        $objResponse->script("\$('abuse_project_popup').toggleClass('b-shadow_hide');");
        $objResponse->script("\$('project_abuse_success').removeClass('b-layout__txt_hide');");
        $objResponse->script("\$('form_abuse').hide();");
        $objResponse->script("setTimeout(\"\$('project_abuse_success').addClass('b-layout__txt_hide')\", 5000);");
        if ($is_moder) {
            $objResponse->script("\$('abuse-cause-error').addClass('b-layout__txt_hide');");
        }
    }
    return $objResponse;
}
Example #2
0
<?php

require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/stdf.php';
require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/userecho.php';
require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/messages.php';
/* 
 * Публикуем запись на UserEcho
 */
$userEcho = new UserEcho();
$result = $userEcho->newTopicComplain('Из теста', 'Не важно');
echo '<p>Результат <strong>newTopic</strong>:</p>';
echo '<pre>';
print_r($result);
echo '</pre>';