mkdir($temp_dir, BX_DIR_PERMISSIONS);
                 }
                 $temp_path = $temp_dir . $temp_file;
                 if (!copy($arFile["tmp_name"], $temp_path)) {
                     $message = new CAdminMessage(array("MESSAGE" => GetMessage("FLOW_ERROR"), "DETAILS" => GetMessage("FLOW_FILEUPLOAD_FILE_CREATE_ERROR") . " \"" . $temp_path . "\"", "TYPE" => "ERROR"));
                 } else {
                     $arFields = array("DOCUMENT_ID" => $ID > 0 ? $ID : "null", "TIMESTAMP_X" => $DB->GetNowFunction(), "MODIFIED_BY" => "'" . $USER->GetID() . "'", "TEMP_FILENAME" => "'" . $DB->ForSql($temp_file, 255) . "'", "FILENAME" => "'" . $DB->ForSql($pathto, 255) . "'", "FILESIZE" => intval($arFile["size"]));
                     $FILE_ID = $DB->Insert("b_workflow_file", $arFields, $err_mess . __LINE__);
                     $arUploadedFiles[] = intval($FILE_ID);
                 }
             }
         }
     }
 }
 if (!$message) {
     $BODY = WFToPath($BODY);
     $arFields = array("MODIFIED_BY" => $USER->GetID(), "TITLE" => $TITLE, "FILENAME" => $FILENAME, "SITE_ID" => $SITE_ID, "BODY" => $BODY, "BODY_TYPE" => $BODY_TYPE, "DATE_LOCK" => false, "LOCKED_BY" => false, "STATUS_ID" => $STATUS_ID, "COMMENTS" => $COMMENTS);
     if ($ID > 0) {
         CWorkflow::Update($arFields, $ID);
     } else {
         if (is_file($DOC_ROOT . $fname)) {
             $filesrc = $APPLICATION->GetFileContent($DOC_ROOT . $FILENAME);
             $arContent = ParseFileContent($filesrc);
             $PROLOG = $arContent["PROLOG"];
             $EPILOG = $arContent["EPILOG"];
         } else {
             for ($i = 0; $i < count($arTemplates); $i++) {
                 if ($arTemplates[$i]["file"] == $template) {
                     $filesrc = GetTemplateContent($arTemplates[$i]["file"]);
                     $arContent = ParseFileContent($filesrc);
                     $PROLOG = $arContent["PROLOG"];
Exemple #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();
 }