/* ADS - DMS - aout 00 - by Ariane Bitoun */ /* Modified - Juin 2001 - by Emmanuel Tollé */ var mot_clef_Name = "BddName";; var mot_clef_Descr = "BddDescr";; var mot_clef_ID = "BddID";; var mot_clef_ID1 = "BddID1";; var mot_clef_ID2 = "BddID2";; var mot_clef_period = "BddPeriod";; var mot_clef_url = "BddUrl";; var mot_clef_path = "BddPath";; var mot_clef_type = "BddType";; var mot_clef_type1 = "BddType1";; var mot_clef_type2 = "BddType2";; var mot_clef_file = "Bddfile";; var mot_clef_int_nul = "-1";; var mot_clef_nul = "arianenil";; var mot_clef_cell_fake = "backstore";; var mot_clef_link_fake = "fake";; var SELECT_SEQ = 1;; var SELECT_MED = 2;; var SELECT_LINK = 3;; var INSERT_SEQ = 4;; var DELETE_SEQ = 5;; var UPDATE_SEQ = 6;; var DELETE_LINK = 7;; var UPDATE_LINK = 8;; var ADD_LINK = 9;; var DELETE_MED = 10;; var UPDATE_MED = 11;; var ADD_MED = 12;; typeof Path = S;; typeof db = SqlDB;; defcom SShow = Show;; defcom SUpdate = Update I I S;; defcom SFeedback = Feedback I I S;; typeof TempSendParam = S;; var MessageMaxSize = 8192;; /*----------------------------------------------------*/ fun _cbSendData (dbconn, param, data) = let param->[cli flag type] in if flag != 0 then let strbuild data::nil -> DataToSend in _DMSsend this cli SUpdate[type 0 DataToSend] else nil; 0 ;; /*----------------------------------------------------*/ fun Extract_Data (cli, flag, type, requete, param) = SqlFetch db @_cbSendData [cli flag type] ; SqlRequest db requete param; if flag != 0 then _DMSsend this cli SUpdate[type 1 nil] else nil; SqlCod db ;; /*----------------------------------------------------*/ fun FindMaxId (requete) = let SqlRequest db requete nil -> lstresult in let hd hd lstresult -> max_id in itoa ((atoi max_id) + 1 ) ;; /*----------------------------------------------------*/ /* cli: client, flag: indicates if the results of the request have to be send by the client, type: voir types predefinis, param: parameters of the request */ fun Send_request (cli, flag, type, param) = if type == SELECT_SEQ /*select the table sequence*/ then ( let "SELECT sequence_description.sequenceid, link_sequence_link.linkid, sequence_description.description, sequence_description.Name, sequence_description.Type_Seq FROM cell_description INNER JOIN (sequence_description INNER JOIN (link3D_description INNER JOIN link_sequence_link ON link3D_description.linkid = link_sequence_link.linkid) ON sequence_description.sequenceid = link_sequence_link.sequenceid) ON cell_description.cellid = link3D_description.cellid WHERE (((link3D_description.name_link)=?) AND ((cell_description.name)=?))" -> requete in let (SQL_CHAR mot_clef_link_fake)::(SQL_CHAR mot_clef_cell_fake)::nil -> myparam in Extract_Data cli flag type requete myparam ) else if type == SELECT_MED /*select the table media*/ then ( let "SELECT DISTINCT media_attribute.mediaid, media_attribute.Name, media_attribute.filename, media_attribute.Path, media_attribute.URL, media_attribute.Type_Media, media_attribute.Origine FROM cell_description INNER JOIN (media_attribute INNER JOIN ((sequence_description INNER JOIN (link3D_description INNER JOIN link_sequence_link ON link3D_description.linkid = link_sequence_link.linkid) ON sequence_description.sequenceid = link_sequence_link.sequenceid) INNER JOIN sequence_media_link ON sequence_description.sequenceid = sequence_media_link.sequenceid) ON media_attribute.mediaid = sequence_media_link.mediaid) ON cell_description.cellid = link3D_description.cellid" -> requete in Extract_Data cli flag type requete nil ) else if type == SELECT_LINK /*select the table sequence_media_link*/ then ( let "SELECT DISTINCT sequence_media_link.sequence_mediaid, sequence_media_link.sequenceid, sequence_media_link.mediaid, sequence_media_link.timelenght FROM cell_description INNER JOIN ((sequence_description INNER JOIN (link3D_description INNER JOIN link_sequence_link ON link3D_description.linkid = link_sequence_link.linkid) ON sequence_description.sequenceid = link_sequence_link.sequenceid) INNER JOIN sequence_media_link ON sequence_description.sequenceid = sequence_media_link.sequenceid) ON cell_description.cellid = link3D_description.cellid" -> requete in Extract_Data cli flag type requete nil ) else if type == INSERT_SEQ /*insert a sequence in table sequence description*/ then let FindMaxId "SELECT MaxIdLink_sequence_link FROM Meta_Ecom" -> maxidseqlink in let FindMaxId "SELECT MaxIdSequence_description FROM Meta_Ecom" -> maxseqid in let strcatn "UPDATE Meta_Ecom SET MaxIdLink_sequence_link="::maxidseqlink::nil -> MetaUpdate in let SqlRequest db MetaUpdate nil -> _ in let strcatn "UPDATE Meta_Ecom SET MaxIdSequence_description="::maxseqid::nil -> MetaUpdate in let SqlRequest db MetaUpdate nil -> _ in let getInfo param mot_clef_Name ->nameseq in let getInfo param mot_clef_Descr-> descrseq in let getInfo param mot_clef_type -> typeseq in let strcatn " INSERT INTO link_sequence_link ( link_sequenceid, sequenceid, linkid ) SELECT "::maxidseqlink::" AS Expr1, "::maxseqid::" AS Expr2, link3D_description.linkid FROM cell_description INNER JOIN link3D_description ON cell_description.cellid = link3D_description.cellid WHERE (((link3D_description.name_link)=?) AND ((link3D_description.type_link)=0) AND ((cell_description.name)=?))"::nil -> requeteseqlink in let (SQL_CHAR mot_clef_link_fake)::(SQL_CHAR mot_clef_cell_fake)::nil -> paramseqlink in let strcatn " INSERT INTO sequence_description (sequenceid, description, name, Type_Seq) VALUES (" ::maxseqid::", '"::descrseq::"', '"::nameseq::"', '"::typeseq::"')"::nil -> requeteseq in ( SqlSetAttr db AUTOCOMMIT_OFF; if (Extract_Data cli 0 type requeteseq nil) == SQL_SUCCESS then if (Extract_Data cli 0 type requeteseqlink paramseqlink) == SQL_SUCCESS then ( SqlCommit db; let (mot_clef_ID1::maxseqid::nil)::(mot_clef_ID2::maxidseqlink::nil)::param -> param in _DMSsend this cli SFeedback[type 1 strbuild param]; nil ) else SqlRollback db else nil; SqlSetAttr db AUTOCOMMIT_ON; nil /* Send_request cli flag SELECT_SEQ nil*/ ) else if type == DELETE_SEQ /*delete a sequence in table sequence description*/ then ( SqlSetAttr db AUTOCOMMIT_OFF; let getInfo param mot_clef_ID ->idseq in let strcat"DELETE * FROM sequence_media_link where sequence_media_link.sequenceid= " idseq ->requete in if (Extract_Data cli 0 type requete nil) == SQL_SUCCESS then let strcat"DELETE * FROM sequence_description where sequence_description.sequenceid= " idseq ->requete in if (Extract_Data cli 0 type requete nil) == SQL_SUCCESS then ( SqlCommit db; _DMSsend this cli SFeedback[type 1 strbuild param]; nil ) else SqlRollback db else nil; SqlSetAttr db AUTOCOMMIT_ON; /* Send_request cli flag SELECT_SEQ nil; Send_request cli flag SELECT_LINK nil */ nil ) else if type == UPDATE_SEQ /*update a sequence in table sequence description*/ then ( let getInfo param mot_clef_ID ->idseq in let getInfo param mot_clef_Name ->nameseq in let getInfo param mot_clef_Descr-> descrseq in let getInfo param mot_clef_type -> typeseq in let strcatn"UPDATE sequence_description SET description='"::descrseq::"', Name='" ::nameseq::"', Type_Seq='"::typeseq::"' WHERE sequenceid="::idseq::nil ->requete in /*Extract_Data cli 0 type requete nil; Send_request cli flag SELECT_SEQ nil */ if (Extract_Data cli 0 type requete nil) == SQL_SUCCESS then _DMSsend this cli SFeedback[type 1 strbuild param] /* a faire*/ else nil; nil ) else if type == DELETE_LINK /*delete a link in table sequence_media_link*/ then ( let getInfo param mot_clef_ID ->idlink in let strcat"DELETE * FROM sequence_media_link where sequence_media_link.sequence_mediaid= " idlink ->requete in /*Extract_Data cli 0 type requete nil;*/ if (Extract_Data cli 0 type requete nil) == SQL_SUCCESS then _DMSsend this cli SFeedback[type 1 strbuild param] /* a faire*/ else nil; nil /*if flag==1 then (Send_request cli flag SELECT_LINK nil) else nil*/ ) else if type == UPDATE_LINK /*delete a link in table sequence_media_link*/ then ( let getInfo param mot_clef_ID ->idlink in let getInfo param mot_clef_ID1 -> idseq in let getInfo param mot_clef_period -> period in let strcatn "UPDATE sequence_media_link SET sequenceid="::idseq::", timelenght=" ::period::" WHERE sequence_media_link.sequence_mediaid="::idlink::nil ->requete in if (Extract_Data cli 0 type requete nil) == SQL_SUCCESS then _DMSsend this cli SFeedback[type 1 strbuild param] else nil; nil /* if flag==1 then (Send_request cli flag SELECT_LINK nil) else nil*/ ) else if type == ADD_LINK /*add a link in table sequence_media_link*/ then ( let FindMaxId "SELECT MaxIdSequence_media_link FROM Meta_Ecom" -> maxid in let strcatn "UPDATE Meta_Ecom SET MaxIdSequence_media_link="::maxid ::nil -> MetaUpdate in let SqlRequest db MetaUpdate nil -> _ in let getInfo param mot_clef_ID ->idmedia in let getInfo param mot_clef_ID1 -> idfakeseq in let getInfo param mot_clef_period -> period in let strcatn "INSERT INTO sequence_media_link (sequence_mediaid, sequenceid, mediaid, timelenght) VALUES ( " ::maxid::", "::idfakeseq::", "::idmedia::", "::period::" )"::nil ->requete in if (Extract_Data cli 0 type requete nil) == SQL_SUCCESS then let (mot_clef_ID2::maxid::nil)::param -> param in _DMSsend this cli SFeedback[type 1 strbuild param] else nil; nil /*Send_request cli flag SELECT_LINK nil*/ ) else if type == UPDATE_MED /*update a media in table media_attribute*/ then ( let getInfo param mot_clef_ID ->id in let getInfo param mot_clef_Name ->name in let getInfo param mot_clef_file ->file in let getInfo param mot_clef_path ->path in let getInfo param mot_clef_url ->url in let getInfo param mot_clef_type ->typem in let getInfo param mot_clef_type1 ->orig in let strcatn"UPDATE media_attribute SET Name='"::name::"', filename='"::file ::"', Path='"::path::"', URL='"::url::"', Type_Media="::typem::", Origine=" ::orig::" WHERE mediaid="::id::nil ->requete in if (Extract_Data cli 0 type requete nil) == SQL_SUCCESS then _DMSsend this cli SFeedback[type 1 strbuild param] else nil; nil /* Send_request cli flag SELECT_MED nil */ ) else if type == ADD_MED /*add a media in table media_attribute */ then ( let FindMaxId "SELECT MaxIdMedia_attribute FROM Meta_Ecom" -> maxid in let FindMaxId "SELECT MaxIdSequence_media_link FROM Meta_Ecom" -> maxidlink in let strcatn "UPDATE Meta_Ecom SET MaxIdMedia_attribute="::maxid ::nil -> MetaUpdate in let SqlRequest db MetaUpdate nil -> _ in let strcatn "UPDATE Meta_Ecom SET MaxIdSequence_media_link="::maxidlink ::nil -> MetaUpdate in let SqlRequest db MetaUpdate nil -> _ in let getInfo param mot_clef_ID ->idseq in let getInfo param mot_clef_Name ->name in let getInfo param mot_clef_file ->file in let getInfo param mot_clef_path ->path in let getInfo param mot_clef_url ->url in let getInfo param mot_clef_type ->typem in let getInfo param mot_clef_type1 ->orig in let strcatn "INSERT INTO media_attribute (mediaid,Name,filename,Path,URL,Type_Media, Origine) VALUES (" ::maxid::", '"::name::"', '"::file::"', '"::path::"', '"::url::"', " ::typem::", "::orig::" )"::nil ->requete in ( SqlSetAttr db AUTOCOMMIT_OFF; if (Extract_Data cli 0 type requete nil) == SQL_SUCCESS then let strcatn "INSERT INTO sequence_media_link (sequence_mediaid, sequenceid,timelenght,mediaid) VALUES (" ::maxidlink::", "::idseq::", "::mot_clef_int_nul::", " ::maxid::")" ::nil ->requete in if (Extract_Data cli 0 type requete nil) == SQL_SUCCESS then ( SqlCommit db; let (mot_clef_ID1::maxid::nil)::param -> param in _DMSsend this cli SFeedback[type 1 strbuild param]; nil ) else SqlRollback db else nil; SqlSetAttr db AUTOCOMMIT_ON; nil ) /*Send_request cli flag SELECT_MED nil;*/ /*Send_request cli flag SELECT_LINK nil */ ) else if type == DELETE_MED /*delete a media*/ then ( let getInfo param mot_clef_ID ->idmed in let strcat "DELETE * FROM sequence_media_link where mediaid= " idmed ->requete in ( SqlSetAttr db AUTOCOMMIT_OFF; if (Extract_Data cli 0 type requete nil) == SQL_SUCCESS then let strcat"DELETE * FROM media_attribute where mediaid= " idmed ->requete in if (Extract_Data cli 0 type requete nil) == SQL_SUCCESS then ( SqlCommit db; _DMSsend this cli SFeedback[type 1 strbuild param]; nil ) /*a faire*/ else SqlRollback db else nil; SqlSetAttr db AUTOCOMMIT_ON; nil ) /*Send_request cli flag SELECT_MED nil; Send_request cli flag SELECT_LINK nil */ ) else nil ;; fun EcritFichier (file, filename) = _storepack file filename /* let _getmodifypack filename -> chemin in let _WtoP chemin -> cheminbis in let _deletepack cheminbis -> _ in let _appendpack file chemin -> succes in 0*/ ;; /*----------------------------------------------------*/ /*Gestion des evenements*/ fun activate (from, concerning, action, param, reply) = if !strcmp action "start" then ( _DMScreateClientDMI this concerning Path; _DMSsend this concerning SShow [] ; Send_request concerning 1 SELECT_SEQ nil; Send_request concerning 1 SELECT_MED nil; Send_request concerning 1 SELECT_LINK nil; 0 ) else 0 ;; /*----------------------------------------------------*/ fun testString (string) = if !strcmp string nil then "" else string ;; /*************************************************************************** **** Renvoie le login ou le password d'une base de donnees, on specifie l'alias dans odbcAlias, l'info que l'on souhaite reccueillir dans info ("login" ou "password") les valeurs sont recuperees dans usmress.ini format : odbc.odbcAlias.login odbc.odbcAlias.password attention : odbcAlias, infos ne doivent pas contenir les caracteres suivants : ".*?" **************************************************************************** ***/ fun GetODBCInfos(odbcAlias,info)= hd switchstr strextr _loadressini strcatn "odbc."::odbcAlias::"."::info::nil ;; /*----------------------------------------------------*/ fun ConnectBdd (DBname) = let testString GetODBCInfos DBname "login" -> Login in let testString GetODBCInfos DBname "password" -> Password in set db = SqlCreate _channel DBname Login Password; if db == nil then _adderror (_loc this "KW_UNABLE_CONNECT" (_DMSgetName this)::DBname::nil ) else nil ;; /*----------------------------------------------------*/ /*fonction appellée lorsque le client se delogue ou destruction*/ fun logout (client) = _DMSevent this client "destroyed" nil nil ;; /*----------------------------------------------------*/ fun IniDMI2 (filename) = let _DMSgetDef this "params" -> param in ( set Path = (getInfo param "path"); ConnectBdd getInfo param "nomdb" ); _DMSregisterDMI this @activate nil @logout nil ;; fun pro () = let BigToAsc BigInvn BigFromAsc _getpack _checkpack "dms/db/ads/ads.conf" BigFromAsc "a06578b679c935e7" -> s in let if (strlen s)!=9 then nil else [htoi substr s 1 4 htoi substr s 5 4] -> [datedebut periode] in if periode==nil then (_adderror strcatn (_loc this "PRO_MODULE" nil)::" "::(_DMSgetName this)::" : "::(_loc this "PRO_INVALID_MSG" nil)::nil;0) else if periode==0 then 1 else let ((time>>1)&0x3fffffff)/43200-datedebut -> x in if x<0 then (_adderror strcatn (_loc this "PRO_MODULE" nil)::" "::(_DMSgetName this)::" : "::(_loc this "PRO_INVALID_MSG" nil)::nil;0) else if x<=periode then (_addwarning strcatn (_loc this "PRO_MODULE" nil)::" "::(_DMSgetName this)::" : "::(_loc this "PRO_LIMITED_MSG" (itoa (periode-x))::nil)::nil;1) else (_adderror strcatn (_loc this "PRO_MODULE" nil)::" "::(_DMSgetName this)::" : "::(_loc this "PRO_ENDLIMITED_MSG" nil)::nil;0) ;; /* Server initialisation */ fun IniDMI (f) = if pro then IniDMI2 f else nil ;; /********************************************** DEFCOM ***********************************************************************************************/ /*----------------------------------------------------*/ fun __Save (flag, type, param) = Send_request DMSsender flag type (strextr param) /*#### manque vérif sur les droits d'admin */ ;; fun __getstreamedmessage (message, filename) = set TempSendParam = if (strlen message) == MessageMaxSize then strcat TempSendParam message else ( exec @EcritFichier with [(strcat TempSendParam message) filename]; "" ); 0 ;; /********************************************** FIN DEFCOM ***********************************************************************************************/