~dont_cache() ~include('../site/admin.header.tmpl','Gestion Interest') ~includeonce('../config/interest.tmpl') ~include('../updateuser.tmpl') ~if(~get('is_admin')==0,~http_error(404)) ~list(~get('database'), "DELETE FROM interest") ~noeval('@arg[1]: res_id @arg[2] res_table @arg[3] publish_timestamp ') ~defunc('fill_interest',' ~list(~get('database'), "SELECT id, ~ifne(~sparam(3), 'insert_timestamp') + 0 AS timestamp FROM ~sparam(2) WHERE ~sparam(2).state=~get('state_ok')", 'LM',' ~set('tmp_id', ~fld('id')) ~set('tmp_score', 0) ~set('tmp_timestamp', ~fld('timestamp')) ~list(~get('database'), "SELECT SUM(IFNULL(score,0)) AS score, ~ifne(~get('interest_coef[~sparam(1)]'),~get('interest_coef_default'))*SUM(IFNULL(score,0))*~get('interest_coef_frequency') AS interest FROM contents_scored WHERE contents_scored.res_id=~integer(~fld('id')) AND contents_scored.res_type=~integer(~sparam(1)) GROUP BY res_type, res_id", 'LM',~set('tmp_score',~fld('score')) ) ~list(~get('database'), "INSERT INTO interest VALUES ( ~integer(~sparam(1)), ~integer(~get('tmp_id')), (~max(~integer(~get('tmp_score')),0)+UNIX_TIMESTAMP(~get('tmp_timestamp'))), ~max(~integer(~get('tmp_score')),0), ~get('tmp_timestamp') )" ) ') ') ~list(~get('database'), "SELECT res_type, res_table, publish_timestamp_field FROM ressources WHERE allow_comments=1", 'LM', ~fill_interest(~fld('res_type'), ~fld('res_table'), ~fld('publish_timestamp_field')) ) ~include("../site/admin.footer.tmpl")