setting vacation as user or admin

  • J.Kruis

    IS there a reason why thera are teo separate module for the user and the admin to active the vacation funtion ( user-vacation and edit-vacation).
    Both modules use virtually the same template and also almost the same php code.

    the user-vacation use the  "get-detail()" from the model / vacation toe get  data form the database
    and edit-vacation use  " $ result = db_query ("SELECT * FROM $ table_vacation WHERE email = '$ fUsername'") "to get data from the database.

    Also there are two methods used for data input form the "POST"
    {                                                                                                                                                                                                         $tSubject = safepost('fSubject');
                                                                                                                                                                                                          $fSubject   = escape_string ($tSubject);

    and user-vacation use

    if ($_SERVER == "POST")
    {  if (isset ($_POST))             $fSubject       = $_POST; }
    this is necessary or has one  advantage over the other method.

    if anyone can gif me some info  than i will see if i can merge these two to one


    jan kruis

  • The answer is: The (more or less) duplicated code has only historical reasons.

    I already removed lots of duplicated code (compare 2.1 to 2.3, for example I removed/merged admin/*), but there are still several duplicates left. (To make things worse, often each copy comes with a different set of bugs. This means I can tell some funny stories about the merging work I have done.)

    If you want to merge edit-vacation and users/vacation, you are more than welcome. It makes the codebase cleaner and makes maintenance easier in the future.

    Please make sure to base your changes on the latest SVN trunk revision. (BTW: I just removed two unused variables from edit-vacation.php ;-)

    To answer your technical questions:

    get_details() from model/vacation is better than the SELECT query

    safepost() is better than accessing $_POST directly because it includes the isset() check and (if needed) allows to give a default value as second parameter

    Oh, and the escape_string() calls are superfluous in the meantime because model/vacation does the escaping itsself. In fact they even count as bug because they add backslashes if the subject or message contain a ' or \ :-(
    (The escape_string() call is only needed for variables that go directly to SQL queries, for example in the SELECT query you cited above - but this query should be replaced with a $vh->get_details() call anyway.)

    You will probably find out that the "perfect" script will be a mix of edit-vacation and users/vacation - both of the existing files have good and not-so-good parts. users/vacation is slightly better because it uses $vh everywhere - but OTOH it uses $_POST directly.
    In other words: you have been warned ;-)

  • J.Kruis

    I will make the merge on the svn trunk

    but please not to many changing .
    I had finnshed me autoreply and interval modifcation  and was ready to upload them when the change with the css came up.

    same as last time

    regards Jan

  • Sorry if I have caused you any trouble ;-)

    However, the changes in other files (like the CSS) shouldn't cause any problems - svn is clever enough to merge them. It can even merge changes in files you edited as long as you didn't edit the same section as I did. Just run "svn up".

    You'll only get a conflict if you have edited the same section of a file that was also modified in SVN. That isn't likely to happen - I know you are working on the vacation module and therefore try to avoid changes in it ;-)