public static function Copy($ID) { global $DB; $err_mess = CVote::err_mess() . "<br>Function: Copy<br>Line: "; $ID = intval($ID); if ($ID <= 0) { return false; } $rCurrentVote = CVote::GetByID($ID); if (!($arCurrentVote = $rCurrentVote->Fetch())) { return false; } unset($arCurrentVote["ID"]); $arCurrentVote['ACTIVE'] = "N"; $newImageId = false; if (intval($arCurrentVote['IMAGE_ID'] > 0)) { $imageId = $arCurrentVote['IMAGE_ID']; $newImageId = CFile::CopyFile($imageId); $arCurrentVote["IMAGE_ID"] = NULL; } $newID = CVote::Add($arCurrentVote); if ($newID === false) { return false; } $DB->Update("b_vote", array("COUNTER" => "0"), "WHERE ID=" . $newID, $err_mess . __LINE__); if ($newImageId) { $DB->Update("b_vote", array("IMAGE_ID" => $newImageId), "WHERE ID=" . $newID, $err_mess . __LINE__); } $state = true; $rQuestions = CVoteQuestion::GetList($ID, $by, $order, array(), $is_filtered); while ($arQuestion = $rQuestions->Fetch()) { $state = $state && CVoteQuestion::Copy($arQuestion['ID'], $newID) !== false; } if ($state == true) { return $newID; } else { return $state; } }
function Copy($ID, $CHECK_RIGHTS = "Y") { global $DB, $APPLICATION, $strError; $err_mess = CAllForm::err_mess() . "<br>Function: Copy<br>Line: "; $ID = intval($ID); if ($CHECK_RIGHTS != "Y" || CForm::IsAdmin()) { $rsForm = CForm::GetByID($ID); $arForm = $rsForm->Fetch(); if (!is_set($arForm, "FORM_TEMPLATE")) { $arForm["FORM_TEMPLATE"] = CForm::GetFormTemplateByID($ID); } // символьный код формы while (true) { $SID = $arForm["SID"]; if (strlen($SID) > 25) { $SID = substr($SID, 0, 25); } $SID .= "_" . RandString(5); $strSql = "SELECT 'x' FROM b_form WHERE SID='" . $DB->ForSql($SID, 50) . "'"; $z = $DB->Query($strSql, false, $err_mess . __LINE__); if (!($zr = $z->Fetch())) { break; } } $arFields = array("NAME" => $arForm["NAME"], "SID" => $SID, "C_SORT" => $arForm["C_SORT"], "FIRST_SITE_ID" => $arForm["FIRST_SITE_ID"], "BUTTON" => $arForm["BUTTON"], "USE_CAPTCHA" => $arForm["USE_CAPTCHA"], "DESCRIPTION" => $arForm["DESCRIPTION"], "DESCRIPTION_TYPE" => $arForm["DESCRIPTION_TYPE"], "SHOW_TEMPLATE" => $arForm["SHOW_TEMPLATE"], "FORM_TEMPLATE" => $arForm["FORM_TEMPLATE"], "USE_DEFAULT_TEMPLATE" => $arForm["USE_DEFAULT_TEMPLATE"], "SHOW_RESULT_TEMPLATE" => $arForm["SHOW_RESULT_TEMPLATE"], "PRINT_RESULT_TEMPLATE" => $arForm["PRINT_RESULT_TEMPLATE"], "EDIT_RESULT_TEMPLATE" => $arForm["EDIT_RESULT_TEMPLATE"], "FILTER_RESULT_TEMPLATE" => $arForm["FILTER_RESULT_TEMPLATE"], "TABLE_RESULT_TEMPLATE" => $arForm["TABLE_RESULT_TEMPLATE"], "STAT_EVENT1" => $arForm["STAT_EVENT1"], "STAT_EVENT2" => $SID, "STAT_EVENT3" => $arForm["STAT_EVENT3"], "arSITE" => CForm::GetSiteArray($ID)); // пункты меню $z = CForm::GetMenuList(array("FORM_ID" => $ID), "N"); while ($zr = $z->Fetch()) { $arFields["arMENU"][$zr["LID"]] = $zr["MENU"]; } // права групп $w = CGroup::GetList($v1 = "dropdown", $v2 = "asc", array("ADMIN" => "N"), $v3); $arGroups = array(); while ($wr = $w->Fetch()) { $arGroups[] = $wr["ID"]; } if (is_array($arGroups)) { foreach ($arGroups as $gid) { $arFields["arGROUP"][$gid] = CForm::GetPermission($ID, array($gid), "Y"); } } // картинка if (intval($arForm["IMAGE_ID"]) > 0) { $arIMAGE = CFile::MakeFileArray(CFile::CopyFile($arForm["IMAGE_ID"])); $arIMAGE["MODULE_ID"] = "form"; $arFields["arIMAGE"] = $arIMAGE; } $NEW_ID = CForm::Set($arFields, 0); if (intval($NEW_ID) > 0) { // статусы $rsStatus = CFormStatus::GetList($ID, $by, $order, array(), $is_filtered); while ($arStatus = $rsStatus->Fetch()) { CFormStatus::Copy($arStatus["ID"], "N", $NEW_ID); } // вопросы/пол¤ $rsField = CFormField::GetList($ID, "ALL", $by, $order, array(), $is_filtered); while ($arField = $rsField->Fetch()) { CFormField::Copy($arField["ID"], "N", $NEW_ID); } } return $NEW_ID; } else { $strError .= GetMessage("FORM_ERROR_ACCESS_DENIED") . "<br>"; } return false; }
function SplitTicket($arParam) { global $DB; $err_mess = CAllTicket::err_mess() . "<br>Function: SplitTicket<br>Line: "; $intLastTicketID = IntVal($arParam['SOURCE_TICKET_ID']); $stLastTicketTitle = htmlspecialcharsEx($arParam['SOURCE_TICKET_TITLE']); $intSplitMesageID = IntVal($arParam['SOURCE_MESSAGE_NUM']); $stSplitMesageDate = MakeTimeStamp($arParam['SOURCE_MESSAGE_DATE'], "DD.MM.YYYY HH:MI:SS") ? $arParam['SOURCE_MESSAGE_DATE'] : ''; // add to the previous post about ticket allocation of posts in a separate branch $arFields = array("MESSAGE_CREATED_USER_ID" => $arParam['SPLIT_MESSAGE_USER_ID'], "MESSAGE_CREATED_MODULE_NAME" => "support", "MESSAGE_CREATED_GUEST_ID" => "null", "MESSAGE_SOURCE_ID" => $arParam['SOURCE_MESSAGE_ID'], "MESSAGE" => GetMessage("SUP_SPLIT_MESSAGE_USER_1", array("#MESSAGE_DATE#" => $stSplitMesageDate, "#TITLE#" => '# ' . $arParam['SPLIT_TICKET_ID'] . ' "' . $arParam['SPLIT_TICKET_TITLE'] . '"')), "LOG" => "N", "HIDDEN" => "N", "NOT_CHANGE_STATUS" => "Y", "MESSAGE_AUTHOR_USER_ID" => $arParam['SPLIT_MESSAGE_USER_ID']); CTicket::AddMessage($intLastTicketID, $arFields, $arFiles = array(), "N"); // add to the previous post about ticket allocation of posts in a separate branch (support log) $arFields_log = array("MESSAGE_CREATED_USER_ID" => $arParam['SPLIT_MESSAGE_USER_ID'], "MESSAGE_CREATED_MODULE_NAME" => "support", "MESSAGE_CREATED_GUEST_ID" => "null", "MESSAGE_SOURCE_ID" => $arParam['SOURCE_MESSAGE_ID'], "MESSAGE" => GetMessage("SUP_SPLIT_MESSAGE_LOG_1", array("#MESSAGE_ID#" => $intSplitMesageID, "#TITLE#" => '<a href="ticket_edit.php?ID=' . $arParam['SPLIT_TICKET_ID'] . '&lang=' . LANGUAGE_ID . '"> # ' . $arParam['SPLIT_TICKET_ID'] . ' "' . $arParam['SPLIT_TICKET_TITLE'] . '"</a>')), "LOG" => "Y"); CTicket::AddMessage($intLastTicketID, $arFields_log, $arFiles_log = array(), "N"); // add a new ticket allocation message posted in a separate branch $arFields = array("MESSAGE_CREATED_USER_ID" => $arParam['SPLIT_MESSAGE_USER_ID'], "MESSAGE_CREATED_MODULE_NAME" => "support", "MESSAGE_CREATED_GUEST_ID" => "null", "MESSAGE_SOURCE_ID" => $arParam['SOURCE_MESSAGE_ID'], "MESSAGE" => GetMessage("SUP_SPLIT_MESSAGE_USER_2", array("#MESSAGE_DATE#" => $stSplitMesageDate, "#TITLE#" => '# ' . $intLastTicketID . ' "' . $stLastTicketTitle . '"')), "LOG" => "N", "HIDDEN" => "N", "NOT_CHANGE_STATUS" => "Y", "MESSAGE_AUTHOR_USER_ID" => $arParam['SPLIT_MESSAGE_USER_ID']); CTicket::AddMessage($arParam['SPLIT_TICKET_ID'], $arFields, $arFiles = array(), "N"); // add a new ticket allocation message posted in a separate branch (support log) $arFields_log = array("MESSAGE_CREATED_USER_ID" => $arParam['SPLIT_MESSAGE_USER_ID'], "MESSAGE_CREATED_MODULE_NAME" => "support", "MESSAGE_CREATED_GUEST_ID" => "null", "MESSAGE_SOURCE_ID" => $arParam['SOURCE_MESSAGE_ID'], "MESSAGE" => GetMessage("SUP_SPLIT_MESSAGE_LOG_2", array("#MESSAGE_ID#" => $intSplitMesageID, "#TITLE#" => '<a href="ticket_edit.php?ID=' . $intLastTicketID . '&lang=' . LANGUAGE_ID . '"> # ' . $intLastTicketID . ' "' . $stLastTicketTitle . '"</a>')), "LOG" => "Y"); CTicket::AddMessage($arParam['SPLIT_TICKET_ID'], $arFields_log, $arFiles_log = array(), "N"); // If the message that we want to separate, there are attached files, copy them if (isset($arParam['SPLIT_ATTACH_FILE'])) { $res = CTicket::GetMessageList($by = 'ID', $order = 'ASC', array('TICKET_ID' => $arParam['SPLIT_TICKET_ID']), $is_filtered = false); $MESSAGE = $res->Fetch(); foreach ($arParam['SPLIT_ATTACH_FILE'] as $key => $iAttachFile) { $fid = CFile::CopyFile(intval($iAttachFile)); if ($fid > 0) { $arFields_fi = array("HASH" => "'" . $DB->ForSql(md5(uniqid(mt_rand(), true) . time()), 255) . "'", "MESSAGE_ID" => $MESSAGE['ID'], "FILE_ID" => $fid, "TICKET_ID" => $arParam['SPLIT_TICKET_ID'], "EXTENSION_SUFFIX" => "null"); $DB->Insert("b_ticket_message_2_file", $arFields_fi, $err_mess . __LINE__); } } } }
/** * <p>Копирует <a href="http://dev.1c-bitrix.ru/api_help/form/terms.php#question">вопрос</a> или <a href="http://dev.1c-bitrix.ru/api_help/form/terms.php#field">поле</a> веб-формы. Возвращает ID нового <a href="http://dev.1c-bitrix.ru/api_help/form/terms.php#question">вопроса</a>/<a href="http://dev.1c-bitrix.ru/api_help/form/terms.php#field">поля</a> в случае положительного результата, в противном случае - "false".</p> * * * @param int $field_id ID <a href="http://dev.1c-bitrix.ru/api_help/form/terms.php#question">вопроса</a>/<a * href="http://dev.1c-bitrix.ru/api_help/form/terms.php#field">поля</a>, который необходимо * скопировать. * * @param string $check_rights = "Y" Флаг необходимости проверки <a * href="http://dev.1c-bitrix.ru/api_help/form/terms.php#permissions">прав</a> текущего * пользователя. Возможны следующие значения: <ul> <li> <b>Y</b> - права * необходимо проверить; </li> <li> <b>N</b> - право не нужно проверять. </li> * </ul> Для копирования <a * href="http://dev.1c-bitrix.ru/api_help/form/terms.php#question">вопроса</a>/<a * href="http://dev.1c-bitrix.ru/api_help/form/terms.php#field">поля</a> необходимо обладать * нижеследующими <a * href="http://dev.1c-bitrix.ru/api_help/form/terms.php#permissions#module">правами</a>: <ol> <li> <b>[25] * просмотр параметров веб-формы</b> на веб-форму, из которой идет * копирование; </li> <li> <b>[30] полный доступ</b> на веб-форму, в которую * копируется </li> </ol> Параметр необязательный. По умолчанию - "Y" * (права необходимо проверить). * * @param mixed $form_id = false ID веб-формы, в которую необходимо скопировать <a * href="http://dev.1c-bitrix.ru/api_help/form/terms.php#question">вопрос</a>/<a * href="http://dev.1c-bitrix.ru/api_help/form/terms.php#field">поле</a>.<br><br> Необязательный * параметр. По умолчанию - "false" (текущая веб-форма). * * @return mixed * * <h4>Example</h4> * <pre> * <? * $FIELD_ID = 140; // ID вопроса * // скопируем вопрос * if ($NEW_FIELD_ID=<b>CFormField::Copy</b>($FIELD_ID)) * { * echo "Вопрос #140 успешно скопирован в новый вопрос #".$NEW_FIELD_ID; * } * else * { * // выведем текст ошибки * global $strError; * echo $strError; * } * ?> * </pre> * * * <h4>See Also</h4> * <ul> <li> <a href="http://dev.1c-bitrix.ru/api_help/form/classes/cform/copy.php">CForm::Copy</a> </li> <li> <a * href="http://dev.1c-bitrix.ru/api_help/form/classes/cformanswer/copy.php">CFormAnswer::Copy</a> </li> <li> <a * href="http://dev.1c-bitrix.ru/api_help/form/classes/cformstatus/copy.php">CFormStatus::Copy</a> </li> </ul><a * name="examples"></a> * * * @static * @link http://dev.1c-bitrix.ru/api_help/form/classes/cformfield/copy.php * @author Bitrix */ public static function Copy($ID, $CHECK_RIGHTS = "Y", $NEW_FORM_ID = false) { global $DB, $strError; $err_mess = CAllFormField::err_mess() . "<br>Function: Copy<br>Line: "; $ID = intval($ID); $NEW_FORM_ID = intval($NEW_FORM_ID); $rsField = CFormField::GetByID($ID); if ($arField = $rsField->Fetch()) { $RIGHT_OK = "N"; if ($CHECK_RIGHTS != "Y" || CForm::IsAdmin()) { $RIGHT_OK = "Y"; } else { $F_RIGHT = CForm::GetPermission($arField["FORM_ID"]); // если имеем право на просмотр параметров формы if ($F_RIGHT >= 25) { // если задана новая форма if ($NEW_FORM_ID > 0) { $NEW_F_RIGHT = CForm::GetPermission($NEW_FORM_ID); // если имеем полный доступ на новую форму if ($NEW_F_RIGHT >= 30) { $RIGHT_OK = "Y"; } } elseif ($F_RIGHT >= 30) { $RIGHT_OK = "Y"; } } } // если права проверили то if ($RIGHT_OK == "Y") { // символьный код поля if (!$NEW_FORM_ID) { while (true) { // change: SID изменяем только если для старой формы. Требование уникальности снято. $SID = $arField["SID"]; if (strlen($SID) > 44) { $SID = substr($SID, 0, 44); } $SID .= "_" . RandString(5); $strSql = "SELECT 'x' FROM b_form WHERE SID='" . $DB->ForSql($SID, 50) . "'"; $z = $DB->Query($strSql, false, $err_mess . __LINE__); if (!($zr = $z->Fetch())) { $strSql = "SELECT 'x' FROM b_form_field WHERE SID='" . $DB->ForSql($SID, 50) . "' AND FORM_ID='" . $arField["FORM_ID"] . "'"; $t = $DB->Query($strSql, false, $err_mess . __LINE__); if (!($tr = $t->Fetch())) { break; } } } } else { $SID = $arField["SID"]; } // копируем $arFields = array("FORM_ID" => $NEW_FORM_ID > 0 ? $NEW_FORM_ID : $arField["FORM_ID"], "ACTIVE" => $arField["ACTIVE"], "TITLE" => $arField["TITLE"], "TITLE_TYPE" => $arField["TITLE_TYPE"], "SID" => $SID, "C_SORT" => $arField["C_SORT"], "ADDITIONAL" => $arField["ADDITIONAL"], "REQUIRED" => $arField["REQUIRED"], "IN_FILTER" => $arField["IN_FILTER"], "IN_RESULTS_TABLE" => $arField["IN_RESULTS_TABLE"], "IN_EXCEL_TABLE" => $arField["IN_EXCEL_TABLE"], "FIELD_TYPE" => $arField["FIELD_TYPE"], "COMMENTS" => $arField["COMMENTS"], "FILTER_TITLE" => $arField["FILTER_TITLE"], "RESULTS_TABLE_TITLE" => $arField["RESULTS_TABLE_TITLE"]); // картинка if (intval($arField["IMAGE_ID"]) > 0) { $arIMAGE = CFile::MakeFileArray(CFile::CopyFile($arField["IMAGE_ID"])); $arIMAGE["MODULE_ID"] = "form"; $arFields["arIMAGE"] = $arIMAGE; } // фильтр $z = CFormField::GetFilterList($arField["FORM_ID"], array("FIELD_ID" => $ID, "FIELD_ID_EXACT_MATCH" => "Y")); while ($zr = $z->Fetch()) { if ($arField["ADDITIONAL"] != "Y") { $arFields["arFILTER_" . $zr["PARAMETER_NAME"]][] = $zr["FILTER_TYPE"]; } elseif ($zr["PARAMETER_NAME"] == "USER") { $arFields["arFILTER_FIELD"][] = $zr["FILTER_TYPE"]; } } //echo "<pre>"; print_r($arFields); echo "</pre>"; $NEW_ID = CFormField::Set($arFields); if (intval($NEW_ID) > 0) { if ($arField["ADDITIONAL"] != "Y") { // ответы $rsAnswer = CFormAnswer::GetList($ID, $by = 'ID', $order = 'ASC', array(), $is_filtered); while ($arAnswer = $rsAnswer->Fetch()) { CFormAnswer::Copy($arAnswer["ID"], $NEW_ID); } // валидаторы $dbValidators = CFormValidator::GetList($ID); while ($arVal = $dbValidators->Fetch()) { CFormValidator::Set($arField['FORM_ID'], $NEW_ID, $arVal['NAME'], $arVal['PARAMS'], $arVal['C_SORT']); } } } return $NEW_ID; } else { $strError .= GetMessage("FORM_ERROR_ACCESS_DENIED") . "<br>"; } } else { $strError .= GetMessage("FORM_ERROR_FIELD_NOT_FOUND") . "<br>"; } return false; }
$arFields["AUTHOR_ID"] = $GLOBALS["USER"]->GetId(); $result = $ID = CVote::Add($arFields); } else { $result = CVote::Update($ID, $arFields); } if (!$result) { $e = $APPLICATION->GetException(); $message = new CAdminMessage(GetMessage("VOTE_GOT_ERROR"), $e); $bVarsFromForm = true; } else { if (isset($_REQUEST['COPYID']) && ($oldID = intval($_REQUEST['COPYID'])) > 0 && ($rCurrentVote = CVote::GetByID($oldID)) && ($arCurrentVote = $rCurrentVote->Fetch())) { global $DB; $newImageId = false; if (intval($arCurrentVote['IMAGE_ID']) > 0 && empty($arIMAGE_ID['name']) && $arIMAGE_ID['del'] != 'Y') { $imageId = $arCurrentVote['IMAGE_ID']; $newImageId = CFile::CopyFile($imageId); $arCurrentVote["IMAGE_ID"] = NULL; } $newID = $ID; if ($newID === false) { return false; } $DB->Update("b_vote", array("COUNTER" => "0"), "WHERE ID=" . $newID, $err_mess . __LINE__); if ($newImageId) { $DB->Update("b_vote", array("IMAGE_ID" => $newImageId), "WHERE ID=" . $newID, $err_mess . __LINE__); } $state = true; $rQuestions = CVoteQuestion::GetList($oldID, $by, $order, array(), $is_filtered); while ($arQuestion = $rQuestions->Fetch()) { $state = $state && CVoteQuestion::Copy($arQuestion['ID'], $newID) !== false; }
public static function PrepareFileForHistory($documentId, $arFileId, $historyIndex) { $dest = self::GenerateFilePath($documentId); $fileParameterIsArray = true; if (!is_array($arFileId)) { $arFileId = array($arFileId); $fileParameterIsArray = false; } $result = array(); foreach ($arFileId as $fileId) { if ($ar = CFile::GetFileArray($fileId)) { $newFilePath = CFile::CopyFile($fileId, false, $dest . "/" . $historyIndex . "/" . $ar["FILE_NAME"]); if ($newFilePath) { $result[] = $newFilePath; } } } if (!$fileParameterIsArray) { if (count($result) > 0) { $result = $result[0]; } else { $result = ""; } } return $result; }
} } elseif (intval($_GET["COPY"]) > 0) { $rsCopy = CTasks::GetByID(intval($_GET["COPY"])); if ($arCopy = $rsCopy->GetNext()) { if (isset($arCopy["~DESCRIPTION_IN_BBCODE"])) { $arCopy["DESCRIPTION_IN_BBCODE"] = $arCopy["~DESCRIPTION_IN_BBCODE"]; } $arCopy["DESCRIPTION"] = $arCopy["~DESCRIPTION"]; $arCopy["CREATED_BY_NAME"] = $arCopy["~CREATED_BY_NAME"]; $arCopy["CREATED_BY_LAST_NAME"] = $arCopy["~CREATED_BY_LAST_NAME"]; $arCopy["CREATED_BY_SECOND_NAME"] = $arCopy["~CREATED_BY_SECOND_NAME"]; $arCopy["CREATED_BY_LOGIN"] = $arCopy["~CREATED_BY_LOGIN"]; $arCopy["MULTITASK"] = "N"; if (sizeof($arCopy["FILES"])) { foreach ($arCopy["FILES"] as $key => $file) { $newFile = CFile::CopyFile($file); $arCopy["FILES"][$key] = $newFile; } } $arCopy['CHECKLIST_ITEMS'] = array(); try { $oTask = new CTaskItem((int) $_GET["COPY"], $loggedInUserId); list($arChecklistItems, $arMetaData) = CTaskCheckListItem::fetchList($oTask, array('SORT_INDEX' => 'ASC')); unset($arMetaData); foreach ($arChecklistItems as $oChecklistItem) { $checklistItemId = -1 * $oChecklistItem->getId(); $arCopy['CHECKLIST_ITEMS'][$checklistItemId] = $oChecklistItem->getData(); $arCopy['CHECKLIST_ITEMS'][$checklistItemId]['ID'] = $checklistItemId; $arCopy['CHECKLIST_ITEMS'][$checklistItemId]['~ID'] = $checklistItemId; $arCopy['CHECKLIST_ITEMS'][$checklistItemId]['META:CAN_MODIFY'] = $oChecklistItem->isActionAllowed(CTaskCheckListItem::ACTION_MODIFY); $arCopy['CHECKLIST_ITEMS'][$checklistItemId]['META:CAN_REMOVE'] = $oChecklistItem->isActionAllowed(CTaskCheckListItem::ACTION_REMOVE);