Ignore:
Timestamp:
May 9, 2011, 4:29:32 PM (13 years ago)
Author:
mistic100
Message:

code cleanup, correct errors with physical pictures

Location:
extensions/Back2Front
Files:
2 deleted
4 edited

Legend:

Unmodified
Added
Removed
  • extensions/Back2Front/Back2Front.php

    r10821 r10823  
    6565  $conf['back2front'] = explode(',',$conf['back2front']);
    6666 
    67   if ($page['page'] == 'picture_modify')
    68   {
    69     /* change values */
    70     if (isset($_POST['b2f_submit']))
    71     {
    72       /* picture is verso */
    73       if (isset($_POST['b2f_is_verso']))
    74       {
    75         /* frontside exists */
    76         if (picture_exists($_POST['b2f_front_id']))
     67  if ($page['page'] != 'picture_modify')
     68  {
     69    return;
     70  }
     71 
     72/* SAVE VALUES */
     73  if (isset($_POST['b2f_submit']))
     74  {
     75    /* picture is verso */
     76    if (isset($_POST['b2f_is_verso']))
     77    {
     78      /* catch all verso and recto ids */
     79      $query = "SELECT image_id, verso_id
     80        FROM ".B2F_TABLE.";";
     81      $all_recto_verso = array_combine(array_from_query($query, 'image_id'), array_from_query($query, 'verso_id'));
     82     
     83      /* verso don't exists */
     84      if (!picture_exists($_POST['b2f_front_id']))
     85      {
     86        $template->append('errors', l10n('Unknown id for frontside picture : ').$_POST['b2f_front_id']);
     87      }
     88      /* verso same as recto  */
     89      else if ($_POST['b2f_front_id'] == $_GET['image_id'])
     90      {
     91        $template->append('errors', l10n('Backside and frontside can\'t be the same picture'));
     92      }
     93      /* recto has already a verso */
     94      else if (in_array($_POST['b2f_front_id'], array_keys($all_recto_verso)))
     95      {
     96          $recto_current_verso['id'] = $all_recto_verso[$_POST['b2f_front_id']];
     97          $recto_current_verso['link'] = get_root_url().'admin.php?page=picture_modify&cat_id=&image_id='.$recto_current_verso['id'];
     98          $template->append('errors', l10n('This picture has already a backside : ').'<a href="'.$recto_current_verso['link'].'">'.$recto_current_verso['id'].'</a>');
     99      }
     100      /* recto is already a verso */
     101      else if (in_array($_POST['b2f_front_id'], array_values($all_recto_verso)))
     102      {
     103          $recto_is_verso['id'] = $_POST['b2f_front_id'];
     104          $recto_is_verso['link'] = get_root_url().'admin.php?page=picture_modify&amp;cat_id=&amp;image_id='.$recto_is_verso['id'];
     105          $template->append('errors', l10n('This picture is already a backside : ').'<a href="'.$recto_is_verso['link'].'">'.$recto_is_verso['id'].'</a>');
     106      }
     107      /* everything is fine */
     108      else
     109      {
     110        // get current categories
     111        $query = "SELECT category_id FROM ".IMAGE_CATEGORY_TABLE." WHERE image_id = ".$_GET['image_id'].";";
     112        $verso_categories = array_from_query($query, 'category_id');
     113       
     114        // insert or update verso associations
     115        pwg_query("INSERT INTO ".B2F_TABLE."
     116          VALUES(".$_POST['b2f_front_id'].", ".$_GET['image_id'].", '".implode(',',$verso_categories)."')
     117          ON DUPLICATE KEY UPDATE image_id = ".$_POST['b2f_front_id'].";");
     118       
     119        // move the verso ?
     120        if (isset($_POST['b2f_move_verso']))
    77121        {
    78           /* search if recto has already a verso */
    79           $query = "SELECT verso_id
    80             FROM ".B2F_TABLE."
    81             WHERE image_id = ".$_POST['b2f_front_id'].";";
    82           $result = pwg_query($query);
    83           list($recto_current_verso['id']) = pwg_db_fetch_row($result);
    84          
    85           if (pwg_db_num_rows($result) AND $recto_current_verso['id'] != $_GET['image_id'])
     122          pwg_query("DELETE FROM ".IMAGE_CATEGORY_TABLE."
     123            WHERE image_id = ".$_GET['image_id'].";");
     124           
     125          pwg_query("INSERT INTO ".IMAGE_CATEGORY_TABLE."
     126            VALUES(".$_GET['image_id'].", ".$conf['back2front'][0].", NULL);");
     127           
     128          // random representant for each categories
     129          set_random_representant($verso_categories);
     130        }
     131     
     132        $template->assign(array(
     133          'B2F_IS_VERSO' => 'checked="checked"',
     134          'B2F_FRONT_ID' => $_POST['b2f_front_id'],
     135        ));
     136       
     137        $template->append('infos', l10n('This picture is now the backside of the picture n° ').$_POST['b2f_front_id']);
     138      }
     139    }
     140    /* picture isn't verso */
     141    else
     142    {
     143      /* search if it was a verso */
     144      $query = "SELECT categories
     145        FROM ".B2F_TABLE."
     146        WHERE verso_id = ".$_GET['image_id'].";";
     147      $result = pwg_query($query);
     148     
     149      /* it must be restored to its original categories (see criteria on maintain.inc) */
     150      if (pwg_db_num_rows($result))
     151      {
     152        // original categories
     153        list($item['categories']) = pwg_db_fetch_row($result);
     154        // catch current categories
     155        $versos_infos = pwg_query("SELECT category_id FROM ".IMAGE_CATEGORY_TABLE." WHERE image_id = ".$_GET['image_id'].";");
     156        while (list($verso_cat) = pwg_db_fetch_row($versos_infos))
     157        {
     158          $current_verso_cats[] = $verso_cat;
     159        }
     160       
     161        /* if verso € 'versos' cat only */
     162        if (count($current_verso_cats) == 1 AND $current_verso_cats[0] == $conf['back2front'][0])
     163        {
     164          foreach (explode(',',$item['categories']) as $cat)
    86165          {
    87             $recto_current_verso['link'] = get_root_url().'admin.php?page=picture_modify&amp;cat_id=&amp;image_id='.$recto_current_verso['id'];
    88             $template->append('errors', l10n('This picture has already a backside : ').'<a href="'.$recto_current_verso['link'].'">'.$recto_current_verso['id'].'</a>');
     166            $datas[] = array(
     167              'image_id' => $_GET['image_id'],
     168              'category_id' => $cat,
     169              );
    89170          }
    90           /* recto is clean */
    91           else
     171          if (isset($datas))
    92172          {
    93             $verso_categories = implode(',',array_keys($template->get_template_vars('associated_options')));
    94             pwg_query("INSERT INTO ".B2F_TABLE."
    95               VALUES(".$_POST['b2f_front_id'].", ".$_GET['image_id'].", '".$verso_categories."')
    96               ON DUPLICATE KEY UPDATE image_id = ".$_POST['b2f_front_id'].";");
    97            
    98             /* move the verso ? */
    99             if (isset($_POST['b2f_move_verso']))
    100             {
    101               pwg_query("DELETE FROM ".IMAGE_CATEGORY_TABLE."
    102                 WHERE image_id = ".$_GET['image_id'].";");
    103                
    104               pwg_query("INSERT INTO ".IMAGE_CATEGORY_TABLE."
    105                 VALUES(".$_GET['image_id'].", ".$conf['back2front'][0].", NULL);");
    106             }
    107          
    108             $template->assign(array(
    109               'B2F_IS_VERSO' => 'checked="checked"',
    110               'B2F_FRONT_ID' => $_POST['b2f_front_id'],
    111             ));
    112            
    113             $template->append('infos', l10n('This picture is now the backside of the picture n° ').$_POST['b2f_front_id']);
     173            mass_inserts(
     174              IMAGE_CATEGORY_TABLE,
     175              array('image_id', 'category_id'),
     176              $datas
     177              );
    114178          }
    115179        }
    116         else
    117         {
    118           $template->append('errors', l10n('Unknown id for frontside picture : ').$_POST['b2f_front_id']);
    119         }
    120       }
    121       /* picture isn't verso */
    122       else
    123       {
    124         /* search if it was a verso */
    125         $query = "SELECT categories
    126           FROM ".B2F_TABLE."
    127           WHERE verso_id = ".$_GET['image_id'].";";
    128         $result = pwg_query($query);
    129        
    130         /* it must be restored to its original categories (see criteria on maintain.inc) */
    131         if (pwg_db_num_rows($result))
    132         {
    133           /* original categories */
    134           list($item['categories']) = pwg_db_fetch_row($result);
    135           /* catch current categories */
    136           $versos_infos = pwg_query("SELECT category_id FROM ".IMAGE_CATEGORY_TABLE." WHERE image_id = ".$_GET['image_id'].";");
    137           while (list($verso_cat) = pwg_db_fetch_row($versos_infos))
    138           {
    139             $current_verso_cats[] = $verso_cat;
    140           }
    141           /* if verso € 'versos' cat only */
    142           if (count($current_verso_cats) == 1 AND $current_verso_cats[0] == $conf['back2front'][0])
    143           {
    144             foreach (explode(',',$item['categories']) as $cat)
    145             {
    146               $datas[] = array(
    147                 'image_id' => $_GET['image_id'],
    148                 'category_id' => $cat,
    149                 );
    150             }
    151             if (isset($datas))
    152             {
    153               mass_inserts(
    154                 IMAGE_CATEGORY_TABLE,
    155                 array('image_id', 'category_id'),
    156                 $datas
    157                 );
    158             }
    159           }
     180       
     181        pwg_query("DELETE FROM ".IMAGE_CATEGORY_TABLE."
     182          WHERE image_id = ".$_GET['image_id']." AND category_id = ".$conf['back2front'][0].";");
     183       
     184        pwg_query("DELETE FROM ".B2F_TABLE."
     185          WHERE verso_id = ".$_GET['image_id'].";");
    160186         
    161           pwg_query("DELETE FROM ".IMAGE_CATEGORY_TABLE."
    162             WHERE image_id = ".$_GET['image_id']." AND category_id = ".$conf['back2front'][0].";");
    163          
    164           pwg_query("DELETE FROM ".B2F_TABLE."
    165             WHERE verso_id = ".$_GET['image_id'].";");
    166            
    167           $template->append('infos', l10n('This picture is no longer a backside'));
    168         }
    169       }
    170     }
    171     /* get saved values */
     187        $template->append('infos', l10n('This picture is no longer a backside'));
     188      }
     189    }
     190  }
     191 
     192/* GET SAVED VALUES */
     193  if ($template->get_template_vars('B2F_IS_VERSO') == null)
     194  {
     195    /* is the picture a verso ? */
     196    $query = "
     197      SELECT image_id
     198      FROM ".B2F_TABLE."
     199      WHERE verso_id = ".$_GET['image_id']."
     200    ;";
     201    $result = pwg_query($query);
     202   
     203    if (pwg_db_num_rows($result))
     204    {
     205      list($recto_id) = pwg_db_fetch_row($result);
     206      $template->assign(array(
     207        'B2F_IS_VERSO' => 'checked="checked"',
     208        'B2F_FRONT_ID' => $recto_id,
     209      ));
     210    }
     211    /* is the picture a front ? */
    172212    else
    173213    {
    174       /* is the pisture a verso ? */
    175       $query = "
    176         SELECT image_id
     214      $query = "SELECT verso_id
    177215        FROM ".B2F_TABLE."
    178         WHERE verso_id = ".$_GET['image_id']."
    179       ;";
     216        WHERE image_id = ".$_GET['image_id'].";";
    180217      $result = pwg_query($query);
    181218     
    182219      if (pwg_db_num_rows($result))
    183220      {
    184         list($recto_id) = pwg_db_fetch_row($result);
     221        include_once(PHPWG_ROOT_PATH.'include/functions_picture.inc.php');
     222       
     223        $item = pwg_db_fetch_assoc($result);
     224        $query = "SELECT id, name, file
     225          FROM ".IMAGES_TABLE."
     226          WHERE id = ".$item['verso_id'].";";
     227        $item = pwg_db_fetch_assoc(pwg_query($query));
     228       
    185229        $template->assign(array(
    186           'B2F_IS_VERSO' => 'checked="checked"',
    187           'B2F_FRONT_ID' => $recto_id,
     230          'B2F_VERSO_ID' => $item['id'],
     231          'B2F_VERSO_URL' => get_root_url().'admin.php?page=picture_modify&amp;cat_id=&amp;image_id='.$item['id'],
     232          'B2F_VERSO_NAME' => get_image_name($item['name'], $item['file']),
    188233        ));
    189234      }
    190       /* is the picture a front ? */
    191       else
    192       {
    193         $query = "SELECT verso_id
    194           FROM ".B2F_TABLE."
    195           WHERE image_id = ".$_GET['image_id'].";";
    196         $result = pwg_query($query);
    197        
    198         if (pwg_db_num_rows($result))
    199         {
    200           include_once(PHPWG_ROOT_PATH.'include/functions_picture.inc.php');
    201          
    202           $item = pwg_db_fetch_assoc($result);
    203           $query = "SELECT id, name, file
    204             FROM ".IMAGES_TABLE."
    205             WHERE id = ".$item['verso_id'].";";
    206           $item = pwg_db_fetch_assoc(pwg_query($query));
    207          
    208           $template->assign(array(
    209             'B2F_VERSO_ID' => $item['id'],
    210             'B2F_VERSO_URL' => get_root_url().'admin.php?page=picture_modify&amp;cat_id=&amp;image_id='.$item['id'],
    211             'B2F_VERSO_NAME' => get_image_name($item['name'], $item['file']),
    212           ));
    213         }
    214       }
    215     }
    216    
    217     $template->set_filename('B2F_picture_modify', dirname(__FILE__).'/template/picture_modify.tpl');
    218     $template->concat('ADMIN_CONTENT', $template->parse('B2F_picture_modify', true));
    219   }
     235    }
     236  }
     237 
     238  $template->set_filename('B2F_picture_modify', dirname(__FILE__).'/template/picture_modify.tpl');
     239  $template->concat('ADMIN_CONTENT', $template->parse('B2F_picture_modify', true));
    220240}
    221241
  • extensions/Back2Front/language/en_UK/plugin.lang.php

    r10821 r10823  
    33$lang['See back'] = 'See back';
    44$lang['See front'] = 'See front';
     5$lang['Modify backside information'] = 'Modify backside information';
    56
    67$lang['This picture is a backside...'] = 'This picture is a backside...';
     
    1011$lang['This picture has a backside : '] = 'This picture has a backside : ';
    1112
     13$lang['Backside and frontside can\'t be the same picture'] = 'Backside and frontside can\'t be the same picture';
    1214$lang['This picture has already a backside : '] = 'This picture has already a backside : ';
     15$lang['This picture id already a backside : '] = 'This picture is already a backside : ';
    1316$lang['This picture is now the backside of the picture n° '] = 'This picture is now the backside of the picture n° ';
    1417$lang['Unknown id for frontside picture : '] = 'Unknown id for frontside picture : ';
  • extensions/Back2Front/language/fr_FR/plugin.lang.php

    r10821 r10823  
    33$lang['See back'] = 'Voir le verso';
    44$lang['See front'] = 'Voir le recto';
     5$lang['Modify backside information'] = 'Modifier les informations du verso';
    56
    67$lang['This picture is a backside...'] = 'Cette image est le verso...';
     
    1011$lang['This picture has a backside : '] = 'Cette image a un verso : ';
    1112
     13$lang['Backside and frontside can\'t be the same picture'] = 'Verso et recto ne peuvent être la même image';
    1214$lang['This picture has already a backside : '] = 'Cette image a déjà un verso : ';
     15$lang['This picture is already a backside : '] = 'Cette image est déjà un verso : ';
    1316$lang['This picture is now the backside of the picture n° '] = 'Cette image est maintenant le verso de l\'image n° ';
    1417$lang['Unknown id for frontside picture : '] = 'Id inconnu pour le recto : ';
  • extensions/Back2Front/template/admin_button.tpl

    r10819 r10823  
    1 <a href="{$VERSO_U_ADMIN}" title="{'Modify verso information'|@translate}" class="pwg-state-default pwg-button" rel="nofollow">
     1{strip}<a href="{$VERSO_U_ADMIN}" title="{'Modify backside information'|@translate}" class="pwg-state-default pwg-button" rel="nofollow">
    22  <span class="pwg-icon pwg-icon-edit"> </span><span class="pwg-button-text">{'edit'|@translate}</span>
    3 </a>
     3</a>{/strip}
Note: See TracChangeset for help on using the changeset viewer.