rejetto forum

cookie and new files

pstar · 5 · 3176

0 Members and 1 Guest are viewing this topic.

Offline pstar

  • Occasional poster
  • *
    • Posts: 4
    • View Profile
i'm new to hfs and here is my 2nd question:
could i use cookie to remember how many new files have been uploaded since my last logon?
now what i see from hfs is the function which can set a timer to mark the new files.
but it cant meet my condition.

thx in advance!


Offline bacter

  • Operator
  • Tireless poster
  • *****
    • Posts: 681
    • View Profile
welcome pstar!

Your question is not clear.

1) Cookies are used to store data of ONE user. This means, you could store in each users pc a cookie with the number he uploaded.

2) If i understand the question in the manner, that you login as the boss and want to control how many uploads where done by all users since your las login, then you should not use a cookie, but a counter in s static variable ( #upload_cnt) that will increment with each upload completed, or add for example the filename and user to a list. Then every time you login, you can look at his counter and list and then clear it.

your computer has no brain - use your own !


Offline pstar

  • Occasional poster
  • *
    • Posts: 4
    • View Profile
thx bacter for  your reply.
what i need is something more like your condition 2.
i'm the admin and i wanna know how many new files have been uploaded to some folders every my logon.
the case is not only one folder.
it's also for time saving, if i find no updating to some folders, i dont have to check it by click the folder's name and to see its sub files.

but, could you give me more info on the static variable?
can the variable keep an eye on a special folder and all its sub-folers for file uploading?

thanks, again!


Offline bacter

  • Operator
  • Tireless poster
  • *****
    • Posts: 681
    • View Profile
Hi pstar

here goes one possible solution for your needs. It uses a counter that says how many files were uploaded since last reset, and creates a file you can load to see all new uploads.

1. Include this at the beginning of the [uppload-sucess] section:
Code: [Select]
{.inc|#uploadcnt.}
{.append|newuploads.htm|<tr><td>
   <a href ="%folder%{.filename|%item-resource%.}">{.filename|%item-resource%.}</a>
   </td><td>{.if|%user%|%user%|%ip%.}</td><td>%timestamp%</td></tr>.}

2.Add this two new sections somewhere in your template:
Code: [Select]
[uploadctrlclear]
{.if|{.=|%user%|admin.}|
{:{.save|newuploads.htm|.}{.set|#uploadcnt|0.}{.$upload-adm.}:}.}

[upload-adm]
{.if|{.=|%user%|admin.}|
{:
<html><head />
<body>
{.if |{.^#uploadcnt.}|
{:
Uploads since last reset: {.^#uploadcnt.}
<table>
<tr><th>Filename</th><th>Uploaded by</th><th>date</th></tr>
{.load|newuploads.htm.}
</table>
<a href="/" style="background-color:darkblue;color:white;">&nbsp;continue&nbsp;</a>{.repeat|4|&nbsp;.}
<a href="~uploadctrlclear" style="background-color:darkblue;color:white;">&nbsp;clear&nbsp; </a>
:}|
{: No new uploads available
<a href="/" style="background-color:darkblue;color:white;">&nbsp;continue&nbsp;</a
:}
.}
</body></html>
:}.}

3. You can then put somwhere in your page a link that is only visible tu you (supposed you are the user 'admin') or invoke that page when you are in root adding ~upload-adm to your url (example: http://localhost/~upload-adm)

In this admin page, once you have seen what you want, you push the clear button and the list will be cleared and the counter reset.

This works as long as your server is not shut down, as then #uploadcnt will be lost. If you need it, you can also save your counter in a file, instead of using a #static variable.

« Last Edit: November 09, 2009, 01:29:30 PM by bacter »
your computer has no brain - use your own !


Offline rejetto

  • Administrator
  • Tireless poster
  • *****
    • Posts: 13510
    • View Profile
Very nice job Bacter,
And you are doing it for the good of people, not for you. Very noble.

To go a step further, i think we can pack such solution in a handier way.

1.
instead of suggesting to append the text to an existing section, you can ask to append this whole text at the end of the template

Code: [Select]
[+upload-success]
...here goes the rest...

so that appending needs less care by the user.

But even more! you should rely on event scripts, since they would not be overwritten in case the user change template for a matter of pure style ;)
So, it would go for  [+upload completed] in Events file.

2.
i think another good point would be to put the rest of your script inside the diff template of a virtual folder named "upload-adm"
this always to avoid overwritings of the template.


I think we should go in a way to make autoinstalling plugins, like for the solution you made. To make it easy to install, similar to the installing procedures we already have for the templates.