function ResetAttachedfiles() { require_once $_SERVER['DOCUMENT_ROOT'] . "/classes/blogs.php"; $objResponse = new xajaxResponse(); require_once $_SERVER['DOCUMENT_ROOT'] . "/classes/attachedfiles.php"; $attachedfiles = new attachedfiles('', true); $asid = $attachedfiles->createSessionID(); $attachedfiles->addNewSession($asid); $objResponse->assign("attachedfiles", "innerHTML", ''); $objResponse->script("\n \t\t\t\t\t\t\t\tvar attachedfiles_list = new Array();\n attachedFiles.init('attachedfiles', \n '{$asid}',\n attachedfiles_list, \n '" . blogs::MAX_FILES . "',\n '" . blogs::MAX_FILE_SIZE . "',\n '" . implode(', ', $GLOBALS['disallowed_array']) . "',\n 'blog',\n '" . get_uid(false) . "'\n );\n\n "); return $objResponse; }
/** * Сохранение Блоги: посты и комментарии * * @param object $objResponse xajaxResponse * @param string $rec_id идентификатор записи * @param string $rec_type тип записи * @param array $aForm массив данных * @param string $sDrawFunc имя функции для выполнения после сохранения */ function _admEditBlogsSaveForm(&$objResponse, $rec_id = '', $rec_type = '', $aForm = array(), $sDrawFunc = '') { require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/attachedfiles.php'; require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/user_content.php'; require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/blogs.php'; $mod = hasPermissions('blogs') ? 0 : 1; $alert = array(); $olduserlogin = $aForm['olduserlogin']; // логин автора блога $close_comments = $aForm['close_comments'] ? 't' : 'f'; // запретить комментирование $is_private = $aForm['is_private'] ? 't' : 'f'; // показывать только мне $ontop = $aForm['ontop'] ? 't' : 'f'; // закрепить тему наверху $categ = change_q_x($aForm['category'], true); // раздел $close_comments = $rec_type == 2 ? 'n' : $close_comments; $is_private = $rec_type == 2 ? 'n' : $is_private; list($gr, $t) = explode('|', $categ); // название, текст if (strlen($aForm['msg']) > blogs::MAX_DESC_CHARS) { $error_flag = 1; $alert[1] = 'Максимальный размер сообщения ' . blogs::MAX_DESC_CHARS . ' символов!'; } $msg = change_q_x(antispam($aForm['msg']), false, false, 'b|br|i|p|ul|li|cut|s|h[1-6]{1}', false, false); $name = substr_entity(change_q_x(antispam($aForm['name']), true, false), 0, 96, true); // ссылка на youtube $yt_link = $aForm['yt_link'] ? $aForm['yt_link'] : ''; if ($yt_link != '') { $v_yt_link = video_validate($yt_link); if (!$v_yt_link) { $alert[4] = 'Неверная ссылка.'; } else { $yt_link = $v_yt_link; } } // опросы $question = substr_entity(change_q_x(antispam(trim((string) $aForm['question'])), false, false, ''), 0, blogs::MAX_POLL_CHARS, true); $multiple = (bool) $aForm['multiple']; $answers = array(); $answers_exists = array(); $i = 0; if (is_array($aForm['answers']) && !empty($aForm['answers'])) { foreach ($aForm['answers'] as $pa) { if (trim((string) $pa) !== '') { $answers[] = substr_entity(change_q_x(antispam(preg_replace('/&/', '&', (string) trim($pa))), false, false, ''), 0, blogs::MAX_POLL_ANSWER_CHARS * 2, true); $i++; } } } if (is_array($aForm['answers_exists']) && !empty($aForm['answers_exists'])) { foreach ($aForm['answers_exists'] as $key => $pa) { if (trim((string) $pa) !== '') { $answers_exists[$key] = substr_entity(change_q_x(antispam(preg_replace('/&/', '&', (string) trim($pa))), false, false, ''), 0, blogs::MAX_POLL_ANSWER_CHARS * 2, true); $i++; } } } if ($i > 0 && $question === '') { $alert[5] = 'Введите текст вопроса'; } else { if ($i > blogs::MAX_POLL_ANSWERS) { $alert[5] = 'Вы можете указать максимум ' . blogs::MAX_POLL_ANSWERS . ' отетов'; } else { if ($i < 2 && $question !== '') { $alert[5] = 'Нужно указать минимум 2 варианта ответа в голосовании'; } } } // файлы $files_session = $aForm['attachedfiles_session']; if (!$files_session) { $attachedfiles = new attachedfiles('', true); $asid = $attachedfiles->createSessionID(); $attachedfiles->addNewSession($asid); $files_session = $asid; } else { $attachedfiles = new attachedfiles($files_session); $asid = $files_session; } $files_info = $attachedfiles->calcFiles(); if ($msg === '' && $question === '' && empty($alert[5]) && !$files_info['count'] && $yt_link === '') { $alert[1] = 'Сообщение не должно быть пустым'; } if (!$alert) { require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/messages.php'; $blogs = new blogs(); $blogs->Edit($_SESSION['uid'], $rec_id, $msg, $name, array(), getRemoteIP(), $err, $mod, '', $gr, $t, array(), $olduserlogin, $yt_link, $close_comments, $is_private, $ontop, null, $question, $answers, $answers_exists, $multiple); $files = $attachedfiles->getFiles(array(1, 3, 4)); $blogs->addAttachedFiles($files, $rec_id, $olduserlogin, false); $attachedfiles->clear(); $sReason = _parseReason($aForm['user_id'], $aForm['adm_edit_text']); messages::blogModifiedNotification($rec_type, $aForm['oldusertitle'], $aForm['post_time'], $aForm['user_name'], $aForm['user_surname'], $olduserlogin, $sReason); $content_id = user_content::MODER_BLOGS; _admEditAfterAll($objResponse, $content_id, $rec_id, $rec_type, $sDrawFunc, $aForm); } else { _setErrors($objResponse, $alert, array(1 => 'msg', 4 => 'yt_link', 5 => 'question'), $sDrawFunc); } }
</div> <div id="letters_div_attach" class="b-file b-file_padleft_80 b-file_padbot_15"> <div id="attachedfiles"> <?php require_once $_SERVER['DOCUMENT_ROOT'] . '/siteadmin/letters/tpl.attachedfiles.php'; ?> </div> <script type="text/javascript"> (function () { var attachedfiles_list = new Array(); <?php require_once $_SERVER['DOCUMENT_ROOT'] . "/classes/attachedfiles.php"; $attachedfiles = new attachedfiles('', true); $asid = $attachedfiles->createSessionID(); $attachedfiles->addNewSession($asid); ?> attachedFiles.initComm( 'attachedfiles', '<?php echo $asid; ?> ', attachedfiles_list, '1', '<?php echo letters::MAX_FILE_SIZE; ?> ', '<?php echo implode(', ', $GLOBALS['disallowed_array']);
/** * Возвращает яваскрипт код для инициализации прикрепленных файлов * * @param array $tmp_files массив прикрепленных файлов * @param int $max_files максимально возможное количество прикрепленных файлов * @param int $max_file_size максимальный размер каждого из прикрепленных файлов * @param string $kind тип записи (contacts, blog и т.д) * @param string $tag_id id html тэга для инициализации прикрепленных файлов * @return string */ function getAttachedFilesJs($tmp_files = array(), $max_files = 0, $max_file_size = 0, $kind = '', $tag_id = 'adm_edit_attachedfiles') { require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/attachedfiles.php'; $sAttach = 'attachedfiles_list = new Array();'; $attachedfiles = new attachedfiles('', true); $attachedfiles_session = $attachedfiles->createSessionID(); $attachedfiles->addNewSession($attachedfiles_session); if ($tmp_files) { $attachedfiles_files = array(); foreach ($tmp_files as $attachedfiles_file) { if ($kind == 'contacts' || $kind == 'project') { $sId = $kind == 'contacts' ? 'id' : 'file_id'; $attachedfiles_files[] = $attachedfiles_file[$sId]; } else { $attachedfiles_files[] = $attachedfiles_file; } } $attachedfiles->setFiles($attachedfiles_files); } $files = $attachedfiles->getFiles(); if ($files) { $n = 0; foreach ($files as $attachedfiles_file) { $sAttach .= "attachedfiles_list[{$n}] = new Object;\n"; $sAttach .= "attachedfiles_list[{$n}].id = '" . md5($attachedfiles_file['id']) . "';\n"; $sAttach .= "attachedfiles_list[{$n}].name = '{$attachedfiles_file['orig_name']}';\n"; $sAttach .= "attachedfiles_list[{$n}].path = '" . WDCPREFIX . "/{$attachedfiles_file['path']}{$attachedfiles_file['name']}';\n"; $sAttach .= "attachedfiles_list[{$n}].size = '" . ConvertBtoMB($attachedfiles_file['size']) . "';\n"; $sAttach .= "attachedfiles_list[{$n}].type = '{$attachedfiles_file['type']}';\n"; $n++; } } $sAttach .= "attachedFiles.init('adm_edit_attachedfiles', '{$attachedfiles_session}', attachedfiles_list, \n '{$max_files}', '{$max_file_size}', '" . implode(', ', $GLOBALS['disallowed_array']) . "',\n '{$kind}', " . get_uid(false) . "\n );"; return $sAttach; }
<?php require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/stdf.php'; require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/CFile.php'; require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/attachedfiles.php'; session_start(); $uid = get_uid(false); if (!$uid) { return; } if (is_array($_POST['attachedfiles_session'])) { reset($_POST['attachedfiles_session']); $_POST['attachedfiles_session'] = current($_POST['attachedfiles_session']); } if (!$_POST['attachedfiles_session']) { $generate_session = attachedfiles::createSessionID(); $_POST['attachedfiles_session'] = $generate_session; } $action = $_POST['attachedfiles_action']; $type = $_POST['attachedfiles_type']; $sess = $_POST['attachedfiles_session']; $attachedfiles = new attachedfiles($sess); switch ($action) { case 'add': if (is_array($_FILES['attachedfiles_file']) && !$_FILES['attachedfiles_file']['error']) { $login = $_SESSION['login']; $dir = $login . '/attach'; $cFile = new CFile($_FILES['attachedfiles_file']); $cFile->table = 'file'; switch ($type) { case 'contacts':
/** * Ресет загрузки файлов. * * @return object xajaxResponse */ function resetAttachedFiles() { $objResponse = new xajaxResponse(); if (hasPermissions('letters') && hasPermissions('adm')) { require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/attachedfiles.php'; $attachedfiles = new attachedfiles('', true); $asid = $attachedfiles->createSessionID(); $attachedfiles->addNewSession($asid); ob_start(); echo '<div id="attachedfiles">'; require_once $_SERVER['DOCUMENT_ROOT'] . '/siteadmin/letters/tpl.attachedfiles.php'; echo '</div>'; echo "<input type='hidden' id='attachedfiles_uid' name='attachedfiles_uid' value='" . get_uid(false) . "'>"; echo "<input type='hidden' id='attachedfiles_action' name='attachedfiles_action' value=''>"; echo "<input type='hidden' id='attachedfiles_delete' name='attachedfiles_delete' value=''>"; echo "<input type='hidden' id='attachedfiles_type' name='attachedfiles_type' value='letters'>"; echo "<input type='hidden' id='attachedfiles_session' name='attachedfiles_session' value='" . $asid . "'>"; echo "<iframe id='attachedfiles_hiddenframe' name='attachedfiles_hiddenframe' style='display:none;'></iframe>"; $html = ob_get_contents(); ob_end_clean(); $objResponse->assign('letters_div_attach', 'innerHTML', $html); $objResponse->script("(function () {\n var attachedfiles_list = new Array();\n\n\n attachedFiles.initComm( 'attachedfiles', \n '{$asid}',\n attachedfiles_list, \n '1',\n '" . letters::MAX_FILE_SIZE . "',\n '" . implode(', ', $GLOBALS['disallowed_array']) . "',\n 'letters',\n '" . get_uid(false) . "'\n );\n })();\n \$('wd_file_add').setStyle('display', 'table');\n "); //$objResponse->script("$('f_button_actionwork').addClass('b-button_rectangle_color_disable');"); $objResponse->script('status_can_submit = true;'); $objResponse->script('if (attachedFiles.newDesign) attachedFiles.initCommDomready();'); } return $objResponse; }