spec/mod/documents.cfm
2025-06-02 16:16:51 +03:00

94 lines
4.0 KiB
Plaintext

<cfimport prefix="m" taglib="../lib"/>
<cfparam name="ATTRIBUTES.section"/>
<cfparam name="ATTRIBUTES.entity"/>
<cfparam name="ATTRIBUTES.id"/>
<cfparam name="ATTRIBUTES.tr"/>
<cfparam name="ATTRIBUTES.writePermitted" type="boolean" default="false"/>
<cfswitch expression="#ATTRIBUTES.section#">
<cfcase value="model">
<cfif isDefined("savedoc") AND #ATTRIBUTES.writePermitted#>
<cftry>
<cfparam name="doc_title" type="string"/>
<m:upload field="doc" output="attach"/>
<cfif !structKeyExists(attach,"binaryData")>
<cfexit method="exittag"/>
</cfif>
<cfif len(attach.binaryData) GT 0 AND len(attach.fileName) GT 0>
<cfquery name="qSave" datasource="#request.DS#">
insert into #ATTRIBUTES.entity#_doc (
#ATTRIBUTES.entity#_id, #ATTRIBUTES.entity#_doc, doc, contenttype, fname,
dt_created, creator_id, dt_updated, updater_id
) values (
<cfqueryparam value=#ATTRIBUTES.id# cfsqltype="CF_SQL_INTEGER" />,
<cfqueryparam value=#doc_title# cfsqltype="CF_SQL_VARCHAR">,
<cfqueryparam value=#attach.binaryData# cfsqltype="CF_SQL_VARBINARY">,
<cfqueryparam value=#attach.contentType# cfsqltype="CF_SQL_VARCHAR">,
<cfqueryparam value=#attach.fileName# cfsqltype="CF_SQL_VARCHAR">,
<cfqueryparam value=#Now()# cfsqltype="CF_SQL_TIMESTAMP" />,
<cfqueryparam value=#request.usr_id# cfsqltype="CF_SQL_INTEGER" />,
<cfqueryparam value=#Now()# cfsqltype="CF_SQL_TIMESTAMP" />,
<cfqueryparam value=#request.usr_id# cfsqltype="CF_SQL_INTEGER" />
)
</cfquery>
</cfif>
<!--- PRG pattern--->
<m:location url="#ATTRIBUTES.tr.selfUrl#"/>
<cfcatch type="ANY"><cfrethrow/></cfcatch>
</cftry>
<cfelse>
<!--- --->
</cfif>
</cfcase>
<cfcase value="view">
<div style="margin:1em 0;">
<b>Документы:</b>
<cfquery name="qDoc" datasource="#request.DS#">
select d.#ATTRIBUTES.entity#_doc_id as doc_id, d.#ATTRIBUTES.entity#_doc as doc_title, d.fname, d.contenttype,
d.dt_created, a.shortname as creator, d.dt_updated, m.shortname as modifier
from #ATTRIBUTES.entity#_doc d
left outer join usr a on (d.creator_id=a.usr_id)
left outer join usr m on (d.updater_id=m.usr_id)
where #ATTRIBUTES.entity#_id=<cfqueryparam cfsqltype="cf_sql_integer" value=#ATTRIBUTES.id#/>
</cfquery>
<cfoutput query="qDoc">
<span class="nw">
<a href="doc_get.cfm?entity=#ATTRIBUTES.entity#&doc_id=#doc_id#" title="открыть (#contenttype#)" target="_blank"><m:contenttype_icon contenttype=#contenttype#/></a>
<cfif #ATTRIBUTES.writePermitted#>
<a href="doc.cfm?entity=#ATTRIBUTES.entity#&doc_id=#doc_id#&#ATTRIBUTES.tr.fwx#" title="редактировать атрибуты"><cfif len(doc_title)>#doc_title#<cfelse>#fname#</cfif></a>
<a href="doc_del.cfm?entity=#ATTRIBUTES.entity#&doc_id=#doc_id#&#ATTRIBUTES.tr.fwx#" title="удалить"><img src="img/del2.png"/></a>
<cfelse>
<cfif len(doc_title)>#doc_title#<cfelse>#fname#</cfif>
</cfif>
</span>
&nbsp; &nbsp;
</cfoutput>
<cfif #ATTRIBUTES.writePermitted#>
<cfoutput>
<form name="frmDoc" action="#request.thisPage#" method="post" enctype="multipart/form-data" style="border:1px solid lightgray; display:inline-block; padding:.1em .5em; background-color:##eee;">
<input type="hidden" name="track" value="#ATTRIBUTES.tr.self#"/>
<input type="hidden" name="#ATTRIBUTES.entity#_id" value="#ATTRIBUTES.id#"/>
Добавить:
<input type="file" name="doc"/>
Название документа:
<input type="text" name="doc_title" value="" size="30"/>
<button type="submit" name="savedoc" class="maincontrol">Загрузить</button>
</form>
</cfoutput>
</cfif>
</div>
</cfcase>
<cfdefaultcase>
<cfoutput>documents: there is no such section "#ATTRIBUTES.section#"</cfoutput>
</cfdefaultcase>
</cfswitch>
<cfexit method="exittag"/><cfqueryparam cfsqltype="cf_sql_bigint"/><cfexit method="exittag"/>