Changeset 11623 for extensions


Ignore:
Timestamp:
Jul 4, 2011, 4:14:36 PM (13 years ago)
Author:
Mattias
Message:

Several bugfixes in batch_single.php

Location:
extensions/Copyrights
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • extensions/Copyrights/TODO

    r11621 r11623  
    44        SOURCES: "loc_begin_admin": http://piwigo.org/forum/viewtopic.php?id=17468
    55                         "use prefilters": http://piwigo.org/forum/viewtopic.php?id=17551&p=2
     6        - This is almost done, except that you need to refresh the batch_unit page, to see the updated copyright
    67- Add Icon field to copyrights
    78- Show the copyright when image is displayed
     
    1213        - Description doesnt show with the copyright info (on the admin page)
    1314        - The warning triangle saying our plugin does not seem compatible (version: ...)
    14         - Cannot create a new copyright???
     15        - Cannot create a new copyright??? (i assume its fixed, but Johan did, so he can remove the todo ;-) )
  • extensions/Copyrights/batch_single.php

    r11622 r11623  
    33// Add a prefilter
    44add_event_handler('loc_end_element_set_unit', 'CR_set_prefilter_batch_single', 55 );
    5 add_event_handler('loc_end_element_set_unit', 'CR_batch_single_submit', 55 );
     5add_event_handler('loc_end_element_set_unit', 'CR_batch_single_submit', 50 );
    66
    77// Change the variables used by the function that changes the template
    8 add_event_handler('loc_begin_admin', 'CR_add_batch_single_vars_to_template');
     8add_event_handler('loc_end_element_set_unit', 'CR_add_batch_single_vars_to_template');
    99
    1010function CR_set_prefilter_batch_single()
     
    2121        $replacement = '<td><strong>{\'Copyright\'|@translate}</strong></td>
    2222                <td>
    23                         {html_options name=copyright-{$element.ID} options=$CRoptions}
     23                        <select id="copyright-{$element.ID}" name="copyright-{$element.ID}">
     24                                <option value="0">--</option>
     25                                {html_options options=$CRoptions selected=$CRcopyrights[$element.ID]}
     26                        </select>
    2427                </td>
    2528        </tr>
     
    5558        }
    5659        $template->assign('CRoptions', $CRoptions);
     60       
     61        // Get the copyright for each element
     62        $query = sprintf(
     63                'SELECT `media_id`, `cr_id`
     64                FROM %s
     65                ;',
     66                COPYRIGHTS_MEDIA);
     67        $result = pwg_query($query);
     68       
     69        $CRcopyrights = array();
     70        while ($row = pwg_db_fetch_assoc($result)) {
     71                $CRcopyrights[$row['media_id']] = $row['cr_id'];
     72        }
     73        $template->assign('CRcopyrights', $CRcopyrights);
    5774}
    5875
    5976function CR_batch_single_submit()
    6077{
    61         // The image id's:
    62         $collection = explode(',', $_POST['element_ids']);
     78        if (isset($_POST['submit']))
     79        {
     80                // The image id's:
     81                $collection = explode(',', $_POST['element_ids']);
    6382
    64         // Delete all existing id's of which the Copyright is going to be set
    65         if (count($collection) > 0) {
    66                 $query = sprintf(
    67                         'DELETE
    68                         FROM %s
    69                         WHERE media_id IN (%s)
    70                         ;',
    71                         COPYRIGHTS_MEDIA, implode(',', $collection));
    72                 pwg_query($query);
    73         }
    74         // Add all Copyrights to an array
    75         $edits = array();
    76         foreach ($collection as $image_id) {
    77                 // The copyright id's
    78                 $crID = pwg_db_real_escape_string($_POST['copyrightID-'.$image_id]);
     83                // Delete all existing id's of which the Copyright is going to be set
     84                if (count($collection) > 0) {
     85                        $query = sprintf(
     86                                'DELETE
     87                                FROM %s
     88                                WHERE media_id IN (%s)
     89                                ;',
     90                                COPYRIGHTS_MEDIA, implode(',', $collection));
     91                        pwg_query($query);
     92                }
     93                // Add all Copyrights to an array
     94                $edits = array();
     95                foreach ($collection as $image_id) {
     96                        // The copyright id's
     97                        $crID = pwg_db_real_escape_string($_POST['copyright-'.$image_id]);
    7998
    80                 array_push(
    81                         $edits,
    82                         array(
    83                                 'media_id' => $image_id,
    84                                 'cr_id' => $crID,
    85                         )
     99                        array_push(
     100                                $edits,
     101                                array(
     102                                        'media_id' => $image_id,
     103               
     104                'cr_id' => $crID,
     105                                )
     106                        );
     107                }
     108                // Add the array to the database
     109                mass_inserts(
     110                        COPYRIGHTS_MEDIA,        // Table name
     111                        array_keys($edits[0]),   // Columns
     112                        $edits                   // Data
    86113                );
    87114        }
    88         // Add the array to the database
    89         mass_inserts(
    90                 COPYRIGHTS_MEDIA,        // Table name
    91                 array_keys($edits[0]),   // Columns
    92                 $edits                   // Data
    93         );
    94115}
    95116
Note: See TracChangeset for help on using the changeset viewer.