PageRenderTime 85ms CodeModel.GetById 49ms RepoModel.GetById 1ms app.codeStats 0ms

/components/bitrix/bizproc.document.history/component.php

https://gitlab.com/alexprowars/bitrix
PHP | 273 lines | 217 code | 19 blank | 37 comment | 52 complexity | aacd9f6ad159b8ffd36b0e283d66c18c MD5 | raw file
  1. <?if(!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED!==true) die();
  2. if (!CModule::IncludeModule('bizproc')):
  3. return false;
  4. endif;
  5. if (!CModule::IncludeModule("webdav")):
  6. ShowError(GetMessage("W_WEBDAV_IS_NOT_INSTALLED"));
  7. return 0;
  8. endif;
  9. require_once($_SERVER["DOCUMENT_ROOT"].BX_ROOT."/components/bitrix/webdav/functions.php");
  10. CUtil::InitJSCore(array('window'));
  11. if (!function_exists("BPWSInitParam"))
  12. {
  13. function BPWSInitParam(&$arParams, $name)
  14. {
  15. $arParams[$name] = trim($arParams[$name]);
  16. if ($arParams[$name] <= 0)
  17. $arParams[$name] = trim($_REQUEST[$name]);
  18. if ($arParams[$name] <= 0)
  19. $arParams[$name] = trim($_REQUEST[mb_strtolower($name)]);
  20. }
  21. }
  22. global $order, $by;
  23. if (empty($_REQUEST["by"])):
  24. $by = "modified";
  25. $order = "desc";
  26. endif;
  27. /********************************************************************
  28. Input params
  29. ********************************************************************/
  30. /***************** BASE ********************************************/
  31. $arParams["MODULE_ID"] = trim(empty($arParams["MODULE_ID"]) ? $_REQUEST["module_id"] : $arParams["MODULE_ID"]);
  32. $arParams["ENTITY"] = trim(empty($arParams["ENTITY"]) ? $_REQUEST["entity"] : $arParams["ENTITY"]);
  33. $arParams["DOCUMENT_TYPE"] = trim(empty($arParams["DOCUMENT_TYPE"]) ? $_REQUEST["document_type"] : $arParams["DOCUMENT_TYPE"]);
  34. $arParams["DOCUMENT_ID"] = trim(empty($arParams["DOCUMENT_ID"]) ? $_REQUEST["document_id"] : $arParams["DOCUMENT_ID"]);
  35. //***************** URL ********************************************/
  36. $URL_NAME_DEFAULT = array(
  37. "document" => "PAGE_NAME=bizproc_document&ID=#ID#");
  38. $arResult["back_url"] = urlencode(empty($_REQUEST["back_url"]) ? $APPLICATION->GetCurPageParam() : $_REQUEST["back_url"]);
  39. foreach ($URL_NAME_DEFAULT as $URL => $URL_VALUE)
  40. {
  41. $arParams[mb_strtoupper($URL)."_URL"] = trim($arParams[mb_strtoupper($URL)."_URL"]);
  42. if (empty($arParams[mb_strtoupper($URL)."_URL"])):
  43. $arParams[mb_strtoupper($URL)."_URL"] = $APPLICATION->GetCurPage();
  44. endif;
  45. $arParams["~".mb_strtoupper($URL)."_URL"] = $arParams[mb_strtoupper($URL)."_URL"];
  46. $arParams[mb_strtoupper($URL)."_URL"] = htmlspecialcharsbx($arParams["~".mb_strtoupper($URL)."_URL"]);
  47. }
  48. /***************** ADDITIONAL **************************************/
  49. $arParams["PAGE_ELEMENTS"] = intval(intVal($arParams["PAGE_ELEMENTS"]) > 0 ? $arParams["PAGE_ELEMENTS"] : 50);
  50. $arParams["PAGE_NAVIGATION_TEMPLATE"] = trim($arParams["PAGE_NAVIGATION_TEMPLATE"]);
  51. $arParams["GRID_ID"] = "bizproc_history_".$arParams["DOCUMENT_ID"][2];
  52. $arParams["ACTION"] = (isset($_REQUEST["action"])? mb_strtolower($_REQUEST["action"]) : '');
  53. $arParams["ACTION"] = (in_array($arParams["ACTION"], array("recover", "delete")) ? $arParams["ACTION"] : '');
  54. $arResult["NOTIFICATIONS"] = array(
  55. "recover" => GetMessage("BPADH_RECOVERY_OK"),
  56. "delete" => GetMessage("BPADH_DELETE_OK"),
  57. );
  58. if (!empty($_REQUEST["result"]) && array_key_exists($_REQUEST["result"], $arResult["NOTIFICATIONS"]))
  59. $arResult["OK_MESSAGE"] = $arResult["NOTIFICATIONS"][$_REQUEST["result"]];
  60. if (isset($arParams["OBJECT"]) && (! is_object($arParams["OBJECT"])))
  61. unset($arParams["OBJECT"]);
  62. /***************** STANDART ****************************************/
  63. $arParams["SET_TITLE"] = ($arParams["SET_TITLE"] == "N" ? "N" : "Y");
  64. $arParams['NAME_TEMPLATE'] = empty($arParams['NAME_TEMPLATE']) ? COption::GetOptionString("bizproc", "name_template", CSite::GetNameFormat(false), SITE_ID) : str_replace(array("#NOBR#","#/NOBR#"), array("",""), $arParams["NAME_TEMPLATE"]);
  65. /********************************************************************
  66. /Input params
  67. ********************************************************************/
  68. /********************************************************************
  69. Main data
  70. ********************************************************************/
  71. $arError = array();
  72. if ($arParams["MODULE_ID"] == '')
  73. $arError[] = array(
  74. "id" => "empty_module_id",
  75. "text" => GetMessage("BPATT_NO_MODULE_ID"));
  76. if ($arParams["ENTITY"] == '')
  77. $arError[] = array(
  78. "id" => "empty_entity",
  79. "text" => GetMessage("BPABS_EMPTY_ENTITY"));
  80. if ($arParams["DOCUMENT_TYPE"] == '')
  81. $arError[] = array(
  82. "id" => "empty_document_type",
  83. "text" => GetMessage("BPABS_EMPTY_DOC_TYPE"));
  84. if ($arParams["DOCUMENT_ID"] == '')
  85. $arError[] = array(
  86. "id" => "empty_document_id",
  87. "text" => GetMessage("BPABS_EMPTY_DOC_ID"));
  88. $arParams["DOCUMENT_TYPE"] = array($arParams["MODULE_ID"], $arParams["ENTITY"], $arParams["DOCUMENT_TYPE"]);
  89. $arParams["DOCUMENT_ID"] = array($arParams["MODULE_ID"], $arParams["ENTITY"], $arParams["DOCUMENT_ID"]);
  90. if (empty($arError))
  91. {
  92. if (!CBPDocument::CanUserOperateDocument(
  93. CBPWebDavCanUserOperateOperation::WriteDocument,
  94. $GLOBALS["USER"]->GetID(),
  95. $arParams["DOCUMENT_ID"],
  96. array("UserGroups" => $GLOBALS["USER"]->GetUserGroupArray()))):
  97. $arError[] = array(
  98. "id" => "access_denied",
  99. "text" => GetMessage("BPADH_NO_PERMS"));
  100. endif;
  101. }
  102. if (!empty($arError))
  103. {
  104. $e = new CAdminException($arError);
  105. ShowError($e->GetString());
  106. return false;
  107. }
  108. /********************************************************************
  109. /Main data
  110. ********************************************************************/
  111. $arResult["VERSIONS"] = array();
  112. $arResult["GRID_VERSIONS"] = array();
  113. $arResult["ERROR_MESSAGE"] = "";
  114. /********************************************************************
  115. Action
  116. ********************************************************************/
  117. if (!empty($arParams['ACTION']) && !empty($_REQUEST["ID"]) && check_bitrix_sessid())
  118. {
  119. $arError = array();
  120. $ID = $_REQUEST["ID"];
  121. switch ($arParams['ACTION'])
  122. {
  123. case "delete":
  124. if ($arParams["MODULE_ID"] == "webdav")
  125. {
  126. if (CBPDocument::CanUserOperateDocument(
  127. CBPWebDavCanUserOperateOperation::DeleteDocument,
  128. $GLOBALS["USER"]->GetID(),
  129. $arParams["DOCUMENT_ID"],
  130. array("UserGroups" => $GLOBALS["USER"]->GetUserGroupArray()))):
  131. CBPHistoryService::Delete($ID, $arParams["DOCUMENT_ID"]);
  132. else:
  133. $arError[] = array(
  134. "id" => "access_denied",
  135. "text" => GetMessage("BPADH_NO_PERMS"));
  136. endif;
  137. }
  138. else
  139. {
  140. CBPHistoryService::Delete($ID, $arParams["DOCUMENT_ID"]);
  141. }
  142. break;
  143. case "recover":
  144. if ($arParams["MODULE_ID"] == "webdav" && isset($arParams["OBJECT"]))
  145. {
  146. $arParams['OBJECT']->IsDir(array('element_id' => $arParams["DOCUMENT_ID"][2]));
  147. if (($arParams["OBJECT"]->workflow == 'bizproc' || $arParams["OBJECT"]->workflow == 'bizproc_limited') &&
  148. $arParams['OBJECT']->arParams['not_found'] == false)
  149. {
  150. CBPDocument::AddDocumentToHistory($arParams['DOCUMENT_ID'], $arParams['OBJECT']->arParams["element_name"], $GLOBALS["USER"]->GetID());
  151. if (method_exists('CIBlockDocumentWebdav', 'TruncateHistory'))
  152. CIBlockDocumentWebdav::TruncateHistory($arParams['OBJECT']->wfParams['DOCUMENT_TYPE'], $arParams["DOCUMENT_ID"][2]);
  153. }
  154. }
  155. try
  156. {
  157. if (!CBPHistoryService::RecoverDocumentFromHistory($ID))
  158. {
  159. $arError[] = array(
  160. "id" => "not recover",
  161. "text" => GetMessage("BPADH_RECOVERY_ERROR"));
  162. }
  163. }
  164. catch (Exception $e)
  165. {
  166. $arError[] = array(
  167. "id" => "not recover",
  168. "text" => $e->getMessage());
  169. }
  170. break;
  171. }
  172. if (!empty($arError)):
  173. $e = new CAdminException($arError);
  174. $arResult["ERROR_MESSAGE"] = $e->GetString();
  175. else:
  176. LocalRedirect($APPLICATION->GetCurPageParam("result=".$arParams["ACTION"], array("action", "ID", "sessid", "result")));
  177. endif;
  178. }
  179. /********************************************************************
  180. /Action
  181. ********************************************************************/
  182. /********************************************************************
  183. Data
  184. ********************************************************************/
  185. $history = new CBPHistoryService();
  186. $db_res = $history->GetHistoryList(
  187. array(mb_strtoupper($by) => mb_strtoupper($order)),
  188. array("DOCUMENT_ID" => $arParams["DOCUMENT_ID"]),
  189. false,
  190. false,
  191. array("ID", "DOCUMENT_ID", "NAME", "MODIFIED", "USER_ID", "USER_NAME", "USER_LAST_NAME", "USER_LOGIN", "DOCUMENT", "USER_SECOND_NAME")
  192. );
  193. if ($db_res)
  194. {
  195. $db_res->NavStart($arParams["PAGE_ELEMENTS"], false);
  196. $arResult["NAV_RESULT"] = $db_res;
  197. $arResult["NAV_STRING"] = $db_res->GetPageNavStringEx($navComponentObject, GetMessage("BPADH_NAV_TITLE"), $arParams["PAGE_NAVIGATION_TEMPLATE"], true);
  198. if ($this->__parent)
  199. $this->__parent->arResult["HISTORY_LENGTH"] = $db_res->NavRecordCount;
  200. while ($res = $db_res->GetNext())
  201. {
  202. if ($arParams['MODULE_ID'] == 'webdav' && isset($arParams['OBJECT']))
  203. {
  204. if (isset($res["DOCUMENT"]["PROPERTIES"]['WEBDAV_SIZE']['VALUE']))
  205. $res['FILE_SIZE'] = CFile::FormatSize($res['DOCUMENT']['PROPERTIES']['WEBDAV_SIZE']['VALUE']);
  206. }
  207. $res["USER"] = CUser::FormatName($arParams["NAME_TEMPLATE"], array("NAME" => $res["USER_NAME"], "LAST_NAME" => $res["USER_LAST_NAME"], "SECOND_NAME" => $res["USER_SECOND_NAME"], "LOGIN" => $res["USER_LOGIN"]), true);
  208. $res["URL"] = array(
  209. "VIEW" => CComponentEngine::MakePathFromTemplate($arParams["~DOCUMENT_URL"], $res),
  210. "RECOVER" => $APPLICATION->GetCurPageParam("ID=".$res["ID"]."&action=recover&".bitrix_sessid_get(), array("ID", "action", "sessid", "result")),
  211. "DELETE" => $APPLICATION->GetCurPageParam("ID=".$res["ID"]."&action=delete&".bitrix_sessid_get(), array("ID", "action", "sessid", "result")));
  212. foreach ($res["URL"] as $key => $val):
  213. $res["URL"]["~".$key] = $val;
  214. $res["URL"][$key] = htmlspecialcharsbx($val);
  215. endforeach;
  216. $arResult["VERSIONS"][$res["ID"]] = $res;
  217. $hintLink = __make_hint($res["DOCUMENT"]["FIELDS"]);
  218. $arResult["GRID_VERSIONS"][$res["ID"]] = array(
  219. "id" => $res["ID"],
  220. "data" => $res,
  221. "actions" => array(
  222. array(
  223. "ICONCLASS" => "bizproc-history-action-recover",
  224. "TEXT" => GetMessage("BPADH_RECOVERY_DOC"),
  225. "ONCLICK" => "jsUtils.Redirect([], '".CUtil::JSEscape($res["URL"]["~RECOVER"])."');"),
  226. array(
  227. "ICONCLASS" => "bizproc-history-action-delete",
  228. "TEXT" => GetMessage("BPADH_DELETE_DOC"),
  229. "ONCLICK" => 'if (confirm(\''.
  230. CUtil::JSEscape(GetMessage("BPADH_DELETE_DOC_CONFIRM")).'\')) {jsUtils.Redirect([], \''.CUtil::JSEscape($res["URL"]["~DELETE"]).'\');}')),
  231. "columns" => array(
  232. "NAME" => $res["DOCUMENT"]["FIELDS"]["HINT"].'<a href="'.$res["URL"]["VIEW"].'" '.$hintLink.'>'.$res["NAME"].'</a>',
  233. //"NAME" => $res["DOCUMENT"]["FIELDS"]["HINT"].'<a href="'.$res["URL"]["VIEW"].'" title="'.GetMessage("BPADH_VIEW_DOC").'" '.$hintLink.'>'.$res["NAME"].'</a>',
  234. //"TAGS" => $res["DOCUMENT"]["FIELDS"]["TAGS"],
  235. //"DESCRIPTION" => $res["DOCUMENT"]["FIELDS"]["PREVIEW_TEXT"],
  236. ),
  237. "editable" => false);
  238. }
  239. }
  240. /********************************************************************
  241. /Data
  242. ********************************************************************/
  243. $this->IncludeComponentTemplate();
  244. /********************************************************************
  245. Standart operations
  246. ********************************************************************/
  247. if($arParams["SET_TITLE"] == "Y")
  248. {
  249. $APPLICATION->SetTitle(GetMessage("BPADH_TITLE"));
  250. }
  251. /********************************************************************
  252. /Standart operations
  253. ********************************************************************/
  254. ?>