Ignore:
Timestamp:
May 9, 2011, 3:15:45 AM (13 years ago)
Author:
mistic100
Message:

use a private album instead a privacy level

File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/Back2Front/Back2Front.php

    r10819 r10821  
    6262function Back2Front_picture_modify()
    6363{
    64   global $page, $template;
     64  global $page, $template, $conf;
     65  $conf['back2front'] = explode(',',$conf['back2front']);
    6566 
    6667  if ($page['page'] == 'picture_modify')
     
    7576        if (picture_exists($_POST['b2f_front_id']))
    7677        {
    77           $query = "
    78             INSERT INTO ".B2F_TABLE."
    79             VALUES(".$_POST['b2f_front_id'].", ".$_GET['image_id'].", ".$_POST['b2f_old_level'].")
    80             ON DUPLICATE KEY UPDATE image_id = ".$_POST['b2f_front_id'].", old_level = ".$_POST['b2f_old_level']."
    81           ;";
    82           pwg_query($query);
    83          
    84           $query = "
    85             UPDATE ".IMAGES_TABLE."
    86             SET level = 99
    87             WHERE id = ".$_GET['image_id']."
    88           ;";
    89           pwg_query($query);
    90          
    91           $template->assign(array(
    92             'B2F_IS_VERSO' => 'checked="checked"',
    93             'B2F_FRONT_ID' => $_POST['b2f_front_id'],
    94             'B2F_OLD_LEVEL' => $_POST['b2f_old_level'],
    95           ));
     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'])
     86          {
     87            $recto_current_verso['link'] = get_root_url().'admin.php?page=picture_modify&cat_id=&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>');
     89          }
     90          /* recto is clean */
     91          else
     92          {
     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']);
     114          }
    96115        }
    97116        else
    98117        {
    99           $template->assign('errors', l10n('Unknown id for frontside picture'));
     118          $template->append('errors', l10n('Unknown id for frontside picture : ').$_POST['b2f_front_id']);
    100119        }
    101120      }
     
    103122      else
    104123      {
    105         $query = "
    106           DELETE FROM ".B2F_TABLE."
    107           WHERE verso_id = ".$_GET['image_id']."
    108         ;";
    109         pwg_query($query);
     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);
    110129       
    111         $query = "
    112           UPDATE ".IMAGES_TABLE."
    113           SET level = ".$_POST['b2f_old_level']."
    114           WHERE id = ".$_GET['image_id']."
    115         ;";
    116         pwg_query($query);
    117        
    118         $template->assign(array(
    119           'level_options_selected' => array($_POST['b2f_old_level']),
    120         ));
     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          }
     160         
     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        }
    121169      }
    122170    }
     
    126174      /* is the pisture a verso ? */
    127175      $query = "
    128         SELECT image_id, old_level
     176        SELECT image_id
    129177        FROM ".B2F_TABLE."
    130178        WHERE verso_id = ".$_GET['image_id']."
     
    134182      if (pwg_db_num_rows($result))
    135183      {
    136         $item = pwg_db_fetch_assoc($result);
     184        list($recto_id) = pwg_db_fetch_row($result);
    137185        $template->assign(array(
    138186          'B2F_IS_VERSO' => 'checked="checked"',
    139           'B2F_FRONT_ID' => $item['image_id'],
    140           'B2F_OLD_LEVEL' => $item['old_level'],
     187          'B2F_FRONT_ID' => $recto_id,
    141188        ));
    142189      }
     
    144191      else
    145192      {
    146         $query = "
    147           SELECT verso_id
     193        $query = "SELECT verso_id
    148194          FROM ".B2F_TABLE."
    149           WHERE image_id = ".$_GET['image_id']."
    150         ;";
     195          WHERE image_id = ".$_GET['image_id'].";";
    151196        $result = pwg_query($query);
    152197       
     
    156201         
    157202          $item = pwg_db_fetch_assoc($result);
    158           $query = "
    159             SELECT id, name, file
     203          $query = "SELECT id, name, file
    160204            FROM ".IMAGES_TABLE."
    161             WHERE id = ".$item['verso_id']."
    162           ;";
     205            WHERE id = ".$item['verso_id'].";";
    163206          $item = pwg_db_fetch_assoc(pwg_query($query));
    164207         
     
    188231}
    189232
    190 
    191 $versos = null; // needs to be declared outside any function for the array_filter callback ?!
    192 /*
    193  * Change/remove navigation thumbnails
    194  */
    195 function Back2Front_items()
    196 {
    197   global $template, $page, $versos;
    198  
    199   /* search all verso ids */
    200   $query = "
    201     SELECT verso_id as id
    202     FROM ".B2F_TABLE."
    203   ;";
    204   $versos = array_values(array_from_query($query, 'id'));
    205  
    206   /* output */
    207   function remove_versos($item)
    208   {
    209     global $versos;
    210     return !in_array($item, $versos);
    211   }
    212   $page['items'] = array_values(array_filter($page['items'], 'remove_versos'));
    213 }
    214 
    215233?>
Note: See TracChangeset for help on using the changeset viewer.