Ignore:
Timestamp:
Mar 17, 2011, 8:25:13 PM (13 years ago)
Author:
mistic100
Message:

[extensions] Contest Results

  • New bloc for PWG Stuffs
  • Use new admin links and javascript implementation
  • Distinguish pending and running contests (both pending before)
File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/ContestResults/admin/results.php

    r9419 r9745  
    88        pwg_query("DELETE FROM " . CR_TABLE_2 . " WHERE `contest_id` = " . $_GET['contest_id'] .";");
    99       
     10        $registered_ids = array();
     11        $_DUPLICATE = array();
     12       
    1013        foreach ($_POST['results'] AS $i => $data) {
    11                 pwg_query("INSERT INTO " . CR_TABLE_2 . "
    12                         (
    13                                 image_id,
    14                                 contest_id,
    15                                 rank,
    16                                 comment,
    17                                 author
    18                         )
    19                         VALUES(
    20                                 '" . $data['image_id'] ."',
    21                                 '" . $_GET['contest_id'] ."',
    22                                 '" . $data['rank'] ."',
    23                                 '" . $data['comment'] ."',
    24                                 '" . $data['author'] . "'
    25                         );");
     14                if (!in_array($data['image_id'], $registered_ids)) {
     15                        $registered_ids[] = $data['image_id'];
     16                       
     17                        pwg_query("INSERT INTO " . CR_TABLE_2 . "
     18                                (
     19                                        image_id,
     20                                        contest_id,
     21                                        rank,
     22                                        comment,
     23                                        author
     24                                )
     25                                VALUES(
     26                                        '" . $data['image_id'] ."',
     27                                        '" . $_GET['contest_id'] ."',
     28                                        '" . $data['rank'] ."',
     29                                        '" . $data['comment'] ."',
     30                                        '" . $data['author'] . "'
     31                                );");
     32               
     33                } else {
     34                        $_DUPLICATE[] = $data;
     35                }
    2636        }
    2737       
    28         redirect(CR_ADMIN . '&tab=results&msg=saved&contest_id=' . $_GET['contest_id']);
     38        if (isset($_GET['redirect']) AND $_GET['redirect'] == 'page') {
     39                redirect(CR_PUBLIC . $_GET['contest_id'] . '-' . str2url(trigger_event('render_CR_content', get_contest_name($_GET['contest_id']))) . '#results');
     40        } else if (!isset($_DUPLICATE)) {
     41                $page['infos'][] = l10n('CR_results_saved');
     42        }
    2943}
    3044
     
    3246//                              Affichage des résultats
    3347// +-----------------------------------------------------------------------+
    34 if (isset($_GET['msg']) AND $_GET['msg'] == 'saved')
    35         array_push($page['infos'], l10n('CR_results_saved'));
     48
     49if (!get_contest_name($_GET['contest_id'])) {
     50        redirect(CR_ADMIN .'-manage&msg=errors.notavailable');
    3651       
    37        
    38 // Nom du concours
    39 $query = "SELECT name FROM " . CR_TABLE_1 . " WHERE id = " . $_GET['contest_id'] . ";";
    40 $contest = pwg_db_fetch_assoc(pwg_query($query));
     52} else {
     53        // Nom du concours
     54        $query = "SELECT name FROM " . CR_TABLE_1 . " WHERE id = " . $_GET['contest_id'] . ";";
     55        $contest = pwg_db_fetch_assoc(pwg_query($query));
    4156
    42 $template->assign(array(
    43         'NAME' => trigger_event('render_CR_content', $contest['name']),
    44         'CONTEST_ID' => $_GET['contest_id']
    45 ));
     57        $template->assign(array(
     58                'NAME' => trigger_event('render_CR_content', $contest['name']),
     59                'CONTEST_ID' => $_GET['contest_id']
     60        ));
    4661
    47 // Résultats
    48 $results = pwg_query("SELECT * FROM " . CR_TABLE_2 . " WHERE contest_id = " . $_GET['contest_id'] . " ORDER BY rank;");
     62        // Résultats en double
     63        if (isset($_DUPLICATE)) {
     64                foreach ($_DUPLICATE AS $result) {
     65                        $data = array(
     66                                'RANK' => 0,
     67                                'IMAGE_ID' => $result['image_id'],
     68                                'AUTHOR' => $result['author'],
     69                                'COMMENT' => $result['comment'],
     70                                'ERROR' => true,
     71                        );
     72                       
     73                        // Infos de l'image
     74                        $image = pwg_query("SELECT id, name, file, path, tn_ext
     75                                FROM " . IMAGES_TABLE . "
     76                                WHERE id = " . $result['image_id'] . ";");
     77                       
     78                        if (!pwg_db_num_rows($image)) {
     79                                $themeconf = $template->get_template_vars('themeconf');
     80                                $data['TN_SRC'] = $themeconf['admin_icon_dir'] . '/errors.png';
     81                                $data['IMAGE_NAME'] = 'N/A';           
     82                        } else {
     83                                $image = pwg_db_fetch_assoc($image);
     84                                $data['TN_SRC'] = get_thumbnail_url($image);
     85                                $data['IMAGE_NAME'] = (empty($image['name'])) ? get_name_from_file($image['file']) : $image['name'];
     86                        }
     87                       
     88                        $page['errors'][] = l10n_dec('CR_duplicate_result %d', 'CR_duplicate_result %d', $result['image_id']);
     89                        $template->append('results', $data);
     90                }
     91        }
    4992
    50 while ($result = pwg_db_fetch_assoc($results)) {
    51         $data = array(
    52                 'RANK' => $result['rank'],
    53                 'IMAGE_ID' => $result['image_id'],
    54                 'AUTHOR' => $result['author'],
    55                 'COMMENT' => $result['comment'],
    56         );
    57        
    58         // Infos de l'image
    59         $image = pwg_query("SELECT id, name, file, path, tn_ext
    60                 FROM " . IMAGES_TABLE . "
    61                 WHERE id = " . $result['image_id'] . ";");
    62        
    63         if (!pwg_db_num_rows($image)) {
    64                 $themeconf = $template->get_template_vars('themeconf');
    65                 $data['TN_SRC'] = $themeconf['admin_icon_dir'] . '/errors.png';
    66                 $data['IMAGE_NAME'] = 'N/A';
    67                 $page['errors'][] = l10n_dec('CR_id_unknown %d', 'CR_id_unknown %d', $result['image_id']);
     93        // Résultats enregistrés
     94        $results = pwg_query("SELECT * FROM " . CR_TABLE_2 . " WHERE contest_id = " . $_GET['contest_id'] . " ORDER BY rank;");
     95
     96        while ($result = pwg_db_fetch_assoc($results)) {
     97                $data = array(
     98                        'RANK' => $result['rank'],
     99                        'IMAGE_ID' => $result['image_id'],
     100                        'AUTHOR' => $result['author'],
     101                        'COMMENT' => $result['comment'],
     102                );
    68103               
    69         } else {
    70                 $image = pwg_db_fetch_assoc($image);
    71                 $data['TN_SRC'] = get_thumbnail_url($image);
    72                 $data['IMAGE_NAME'] = (empty($image['name'])) ? get_name_from_file($image['file']) : $image['name'];
     104                // Infos de l'image
     105                $image = pwg_query("SELECT id, name, file, path, tn_ext
     106                        FROM " . IMAGES_TABLE . "
     107                        WHERE id = " . $result['image_id'] . ";");
     108               
     109                if (!pwg_db_num_rows($image)) {
     110                        $themeconf = $template->get_template_vars('themeconf');
     111                        $data['TN_SRC'] = $themeconf['admin_icon_dir'] . '/errors.png';
     112                        $data['IMAGE_NAME'] = 'N/A';
     113                        $data['ERROR'] = true;
     114                        $page['errors'][] = l10n_dec('CR_id_unknown %d', 'CR_id_unknown %d', $result['image_id']);
     115                } else {
     116                        $image = pwg_db_fetch_assoc($image);
     117                        $data['TN_SRC'] = get_thumbnail_url($image);
     118                        $data['IMAGE_NAME'] = (empty($image['name'])) ? get_name_from_file($image['file']) : $image['name'];
     119                }
     120               
     121                $template->append('results', $data);
    73122        }
    74        
    75         $template->append('results', $data);
     123
     124        // +-----------------------------------------------------------------------+
     125        //                              Template
     126        // +-----------------------------------------------------------------------+
     127        $template->set_filenames(array('plugin_admin_content' => dirname(__FILE__) . '/template/results.tpl'));
     128        $template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content');
    76129}
    77130
    78 // +-----------------------------------------------------------------------+
    79 //                              Template
    80 // +-----------------------------------------------------------------------+
    81 $template->set_filenames(array('plugin_admin_content' => dirname(__FILE__) . '/template/results.tpl'));
    82 $template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content');
    83131?>
Note: See TracChangeset for help on using the changeset viewer.