示例#1
0
	public static function Update($arFields, $DOCUMENT_ID)
	{
		$err_mess = (CWorkflow::err_mess())."<br>Function: Update<br>Line: ";
		global $DB;
		$z = CWorkflow::GetByID($DOCUMENT_ID);
		$change = false;
		if ($zr=$z->Fetch())
		{
			if ($zr["STATUS_ID"]	!=	$DB->ForSql($arFields["STATUS_ID"]) or
				$zr["BODY"]			!=	$DB->ForSql($arFields["BODY"])		or
				$zr["BODY_TYPE"]	!=	$DB->ForSql($arFields["BODY_TYPE"])	or
				$zr["COMMENTS"]		!=	$DB->ForSql($arFields["COMMENTS"])	or
				$zr["FILENAME"]		!=	$DB->ForSql($arFields["FILENAME"])	or
				$zr["SITE_ID"]		!=	$DB->ForSql($arFields["SITE_ID"])	or
				$zr["TITLE"]		!=	$DB->ForSql($arFields["TITLE"]))
				$change = true;
		}
		$strUpdate = $DB->PrepareUpdate("b_workflow_document", $arFields, "workflow");
		$strSql = "UPDATE b_workflow_document SET ".$strUpdate.", DATE_MODIFY=now(), DATE_ENTER=now() WHERE ID=".$DOCUMENT_ID;
		$DB->Query($strSql, false, $err_mess.__LINE__);
		if ($change)
		{
			$LOG_ID = CWorkflow::SetHistory($DOCUMENT_ID);
			CWorkflow::SetMove($DOCUMENT_ID, $arFields["STATUS_ID"], $zr["STATUS_ID"], $LOG_ID);
		}
	}
示例#2
0
 public static function SetStatus($DOCUMENT_ID, $STATUS_ID, $OLD_STATUS_ID, $history = true)
 {
     $err_mess = CAllWorkflow::err_mess() . "<br>Function: SetStatus<br>Line: ";
     global $DB, $APPLICATION, $USER, $strError;
     //$arMsg = Array();
     $DOCUMENT_ID = intval($DOCUMENT_ID);
     $STATUS_ID = intval($STATUS_ID);
     $OLD_STATUS_ID = intval($OLD_STATUS_ID);
     if ($STATUS_ID == 1) {
         // get all files associated with the document
         $files = CWorkflow::GetFileList($DOCUMENT_ID);
         while ($file = $files->Fetch()) {
             $path = $file["FILENAME"];
             $DOC_ROOT = CSite::GetSiteDocRoot($file["SITE_ID"]);
             $pathto = $DOC_ROOT . $path;
             $pathfrom = CWorkflow::GetTempDir() . $file["TEMP_FILENAME"];
             if ($USER->CanDoFileOperation('fm_edit_in_workflow', array($file["SITE_ID"], $path)) && $USER->CanDoFileOperation('fm_edit_existent_file', array($file["SITE_ID"], $path)) && $USER->CanDoFileOperation('fm_create_new_file', array($file["SITE_ID"], $path))) {
                 if (!copy($pathfrom, $pathto)) {
                     $str = GetMessage("FLOW_CAN_NOT_WRITE_FILE", array("#FILENAME#" => $path));
                     $strError .= $str . "<br>";
                 }
             } else {
                 $str = GetMessage("FLOW_ACCESS_DENIED_FOR_FILE_WRITE", array("#FILENAME#" => $path));
                 $strError .= $str . "<br>";
             }
         }
         // still good
         if (strlen($strError) <= 0) {
             // publish the document
             $y = CWorkflow::GetByID($DOCUMENT_ID);
             $yr = $y->Fetch();
             if ($USER->CanDoFileOperation('fm_edit_in_workflow', array($yr["SITE_ID"], $yr["FILENAME"])) && $USER->CanDoFileOperation('fm_edit_existent_file', array($yr["SITE_ID"], $yr["FILENAME"])) && $USER->CanDoFileOperation('fm_create_new_file', array($yr["SITE_ID"], $yr["FILENAME"]))) {
                 // save file
                 $prolog = $yr["PROLOG"];
                 if (strlen($prolog) > 0) {
                     $title = $yr["TITLE"];
                     $prolog = SetPrologTitle($prolog, $title);
                 }
                 $content = $yr["BODY_TYPE"] == "text" ? TxtToHTML($yr["BODY"]) : $yr["BODY"];
                 $content = WFToPath($content);
                 $epilog = $yr["EPILOG"];
                 $filesrc = $prolog . $content . $epilog;
                 global $BX_WORKFLOW_PUBLISHED_PATH, $BX_WORKFLOW_PUBLISHED_SITE;
                 $BX_WORKFLOW_PUBLISHED_PATH = $yr["FILENAME"];
                 $BX_WORKFLOW_PUBLISHED_SITE = $yr["SITE_ID"];
                 $DOC_ROOT = CSite::GetSiteDocRoot($yr["SITE_ID"]);
                 $APPLICATION->SaveFileContent($DOC_ROOT . $yr["FILENAME"], $filesrc);
                 $BX_WORKFLOW_PUBLISHED_PATH = "";
                 $BX_WORKFLOW_PUBLISHED_SITE = "";
             } else {
                 // throw error
                 $str = GetMessage("FLOW_ACCESS_DENIED_FOLDER", array("#FILENAME#" => $yr["FILENAME"]));
                 $strError .= GetMessage("FLOW_ERROR") . htmlspecialcharsbx($str) . "<br>";
             }
         }
     }
     if (strlen($strError) <= 0) {
         // update db
         $arFields = array("DATE_MODIFY" => $DB->GetNowFunction(), "MODIFIED_BY" => $USER->GetID(), "STATUS_ID" => intval($STATUS_ID));
         $DB->Update("b_workflow_document", $arFields, "WHERE ID='" . $DOCUMENT_ID . "'", $err_mess . __LINE__);
         if ($history === true) {
             $LOG_ID = CWorkflow::SetHistory($DOCUMENT_ID);
             CWorkflow::SetMove($DOCUMENT_ID, $STATUS_ID, $OLD_STATUS_ID, $LOG_ID);
         }
     } else {
         $strError = GetMessage("FLOW_DOCUMENT_NOT_PUBLISHED") . "<br>" . $strError;
     }
     CWorkflow::CleanUpPublished();
 }