Ignore:
Timestamp:
Jul 9, 2011, 3:30:34 PM (13 years ago)
Author:
Mattias
Message:

Fixed bugs in modify.php, it works now, though it still looks awfull :-/
Added language for the error message in admin.php

File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/Copyrights/modify.php

    r11638 r11675  
    33// Add a prefilter
    44add_event_handler('loc_begin_admin', 'CR_set_prefilter_modify', 50 );
    5 add_event_handler('loc_end_admin', 'CR_modify_submit', 50 );
     5add_event_handler('loc_begin_admin', 'CR_modify_submit', 50 );
    66
    77// Change the variables used by the function that changes the template
    8 add_event_handler('loc_end_admin', 'CR_add_modify_vars_to_template');
     8add_event_handler('loc_begin_admin', 'CR_add_modify_vars_to_template');
    99
    1010function CR_set_prefilter_modify()
     
    2323                        <select id="copyright" name="copyright">
    2424                                <option value="0">--</option>
    25                                 {html_options options=$CRoptions selected=$CRcopyrights[$CRid]}
     25                                {html_options options=$CRoptions selected=$CRid}
    2626                        </select>
    2727                </td>
     
    3636function CR_add_modify_vars_to_template()
    3737{
    38         global $template;
     38        // Check if we are at the modify page (the problem is that this will send the stuff to every admin page that has an ?image_id...
     39        if (isset($_GET['image_id']))
     40        {
     41                global $template;
    3942
    40         load_language('plugin.lang', dirname(__FILE__).'/');
     43                load_language('plugin.lang', dirname(__FILE__).'/');
    4144
    42         // Fetch all the copyrights and assign them to the template
    43         $query = sprintf(
    44                 'SELECT `cr_id`,`name`
    45                 FROM %s
    46                 WHERE `visible`<>0
    47                 ;',
    48                 COPYRIGHTS_ADMIN);
    49         $result = pwg_query($query);
     45                // Fetch all the copyrights and assign them to the template
     46                $query = sprintf(
     47                        'SELECT `cr_id`,`name`
     48                        FROM %s
     49                        WHERE `visible`<>0
     50                        ;',
     51                        COPYRIGHTS_ADMIN);
     52                $result = pwg_query($query);
    5053
    51         $CRoptions = array();
    52         while ($row = pwg_db_fetch_assoc($result)) {
    53                 $CRoptions[$row['cr_id']] = $row['name'];
     54                $CRoptions = array();
     55                while ($row = pwg_db_fetch_assoc($result)) {
     56                        $CRoptions[$row['cr_id']] = $row['name'];
     57                }
     58                $template->assign('CRoptions', $CRoptions);
     59               
     60                // Get the current Copyright
     61                $image_id = $_GET['image_id'];
     62                $query = sprintf(
     63                        'SELECT `media_id`, `cr_id`
     64                        FROM %s
     65                        WHERE `media_id` = %d
     66                        ;',
     67                        COPYRIGHTS_MEDIA, $image_id);
     68                $result = pwg_query($query);
     69               
     70                $CRid = 0; // Default is '--'
     71                while ($row = pwg_db_fetch_assoc($result)) {
     72                        $CRid = $row['cr_id'];
     73                }
     74                $template->assign('CRid', $CRid);
    5475        }
    55         $template->assign('CRoptions', $CRoptions);
    56        
    57         // Get the current Copyright
    58         $image_id = $_GET['image_id']);
    59         $query = sprintf(
    60                 'SELECT `media_id`, `cr_id`
    61                 FROM %s
    62     WHERE `media_id` = %d
    63                 ;',
    64                 COPYRIGHTS_MEDIA, $image_id);
    65         $result = pwg_query($query);
    66        
    67   $CRid = 0; // Default is '--'
    68         while ($row = pwg_db_fetch_assoc($result)) {
    69                 $CRid = $row['cr_id'];
    70         }
    71         $template->assign('CRid', $CRid);
    7276}
    7377
    7478function CR_modify_submit()
    7579{
    76         if (isset($_POST['submit']))
     80        // Check if we are at the modify page (the problem is that this will send the stuff to every admin page that has an ?image_id...
     81        if (isset($_GET['image_id']))
    7782        {
    78                 // The data from the submit
    79                 $image_id = $_GET['image_id']);
    80     $CRid = $_POST['copyright'];
     83                if (isset($_POST['submit']))
     84                {
     85                        // The data from the submit
     86                        $image_id = $_GET['image_id'];
     87                        $CRid = $_POST['copyright'];
    8188
    82                 // Delete the Copyright if it allready exists
     89                        // Delete the Copyright if it allready exists
     90                        $query = sprintf(
     91                                'DELETE
     92                                FROM %s
     93                                WHERE `media_id` = %d
     94                                ;',
     95                                COPYRIGHTS_MEDIA, $image_id);
     96                        pwg_query($query);
     97
     98                // Insert the Copyright
    8399                $query = sprintf(
    84                         'DELETE
    85                         FROM %s
    86                         WHERE `media_id` = %d
    87                         ;',
    88                         COPYRIGHTS_MEDIA, $image_id);
     100                  'INSERT INTO %s
     101                  VALUES (%d, %d)
     102                  ;',
     103                  COPYRIGHTS_MEDIA, $image_id, $CRid);
    89104                pwg_query($query);
    90 
    91     // Insert the Copyright
    92     $query = sprintf(
    93       'INSERT INTO %s
    94       VALUES (%d, %d)
    95       ;',
    96       COPYRIGHTS_MEDIA, $image_id, $CRid);
    97     pwg_query($query);
     105                }
    98106        }
    99107}
Note: See TracChangeset for help on using the changeset viewer.