Changeset 68


Ignore:
Timestamp:
Sep 7, 2003, 12:14:33 PM (21 years ago)
Author:
z0rglub
Message:

Virtual categories management

Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/admin/cat_list.php

    r57 r68  
    2121//----------------------------------------------------- template initialization
    2222$sub = $vtp->Open( '../template/'.$user['template'].'/admin/cat_list.vtp' );
    23 // language
    24 $vtp->setGlobalVar( $sub, 'cat_edit',        $lang['cat_edit'] );
    25 $vtp->setGlobalVar( $sub, 'cat_up',          $lang['cat_up'] );
    26 $vtp->setGlobalVar( $sub, 'cat_down',        $lang['cat_down'] );
    27 $vtp->setGlobalVar( $sub, 'cat_image_info',  $lang['cat_image_info'] );
    28 $vtp->setGlobalVar( $sub, 'cat_permission',  $lang['cat_permission'] );
    29 $vtp->setGlobalVar( $sub, 'cat_update',      $lang['cat_update'] );
    30 $vtp->setGlobalVar( $sub, 'user_template',   $user['template'] );
     23$tpl = array( 'cat_edit','cat_up','cat_down','cat_image_info',
     24              'cat_permission','cat_update','cat_add','cat_parent','submit',
     25              'cat_virtual','delete','cat_first','cat_last' );
     26templatize_array( $tpl, 'lang', $sub );
     27$vtp->setGlobalVar( $sub, 'user_template', $user['template'] );
     28//--------------------------------------------------- adding a virtual category
     29$errors = array();
     30if ( isset( $_POST['submit'] ) )
     31{
     32  if ( !preg_match( '/^\s*$/', $_POST['virtual_name'] ) )
     33  {
     34    // we have then to add the virtual category
     35    $query = 'INSERT INTO '.PREFIX_TABLE.'categories';
     36    $query.= ' (name,id_uppercat) VALUES ';
     37    if ( $_POST['associate'] == -1 )
     38    {
     39      $_POST['associate'] = 'NULL';
     40    }
     41    $query.= " ('".$_POST['virtual_name']."',".$_POST['associate'].")";
     42    $query.= ';';
     43    echo $query;
     44    mysql_query( $query );
     45  }
     46  else
     47  {
     48    array_push( $errors, $lang['cat_error_name'] );
     49  }
     50}
    3151//---------------------------------------------------------------  rank updates
    32 if ( isset( $_GET['up'] ) && is_numeric( $_GET['up'] ) )
     52if ( isset( $_GET['up'] ) and is_numeric( $_GET['up'] ) )
    3353{
    3454  // 1. searching level (id_uppercat)
     
    7292  mysql_query( $query );
    7393}
    74 if ( isset( $_GET['down'] ) && is_numeric( $_GET['down'] ) )
     94if ( isset( $_GET['down'] ) and is_numeric( $_GET['down'] ) )
    7595{
    7696  // 1. searching level (id_uppercat)
     
    90110  if ( $level == '' )
    91111  {
    92     $query.= ' AND id_uppercat is null';
     112    $query.= ' AND id_uppercat IS NULL';
    93113  }
    94114  else
     
    113133  $query.= ';';
    114134  mysql_query( $query );
     135}
     136if ( isset( $_GET['last'] ) and is_numeric( $_GET['last'] ) )
     137{
     138  // 1. searching level (id_uppercat) of the category to move
     139  $query = 'SELECT id_uppercat,rank';
     140  $query.= ' FROM '.PREFIX_TABLE.'categories';
     141  $query.= ' WHERE id = '.$_GET['last'];
     142  $query.= ';';
     143  $row = mysql_fetch_array( mysql_query( $query ) );
     144  $level = $row['id_uppercat'];
     145  // 2. searching the highest rank of the categories of the same parent
     146  $query = 'SELECT MAX(rank) AS max_rank';
     147  $query.= ' FROM '.PREFIX_TABLE.'categories';
     148  $query.= ' WHERE id_uppercat';
     149  if ( $level == '' ) $query.= ' IS NULL';
     150  else                $query.= ' = '.$level;
     151  $query.= ';';
     152  $row = mysql_fetch_array( mysql_query( $query ) );
     153  $max_rank = $row['max_rank'];
     154  // 3. updating the rank of our category to be after the previous max rank
     155  $query = 'UPDATE '.PREFIX_TABLE.'categories';
     156  $query.= ' SET rank = '.($max_rank + 1);
     157  $query.= ' WHERE id = '.$_GET['last'];
     158  $query.= ';';
     159  mysql_query( $query );
     160}
     161if ( isset( $_GET['first'] ) and is_numeric( $_GET['first'] ) )
     162{
     163  // to place our category as first, we simply say that is rank is 0, then
     164  // reordering will move category ranks correctly (first rank should be 1
     165  // and not 0)
     166  $query = 'UPDATE '.PREFIX_TABLE.'categories';
     167  $query.= ' SET rank = 0';
     168  $query.= ' WHERE id = '.$_GET['first'];
     169  $query.= ';';
     170  mysql_query( $query );
     171}
     172if ( isset( $_GET['delete'] ) and is_numeric( $_GET['delete'] ) )
     173{
     174  delete_category( $_GET['delete'] );
    115175}
    116176//------------------------------------------------------------------ reordering
     
    143203  }
    144204}
    145        
    146205ordering( 'NULL' );
    147 //----------------------------------------------------affichage de la page
     206//-------------------------------------------------------------- errors display
     207if ( count( $errors ) != 0 )
     208{
     209  $vtp->addSession( $sub, 'errors' );
     210  foreach ( $errors as $error ) {
     211    $vtp->addSession( $sub, 'li' );
     212    $vtp->setVar( $sub, 'li.content', $error );
     213    $vtp->closeSession( $sub, 'li' );
     214  }
     215  $vtp->closeSession( $sub, 'errors' );
     216}
     217//---------------------------------------------------------------- page display
    148218function display_cat_manager( $id_uppercat, $indent,
    149219                              $uppercat_visible, $level )
    150220{
    151   global $lang,$conf,$sub,$vtp;
     221  global $lang,$conf,$sub,$vtp,$page;
    152222               
    153223  // searching the min_rank and the max_rank of the category
     
    171241  $td    = 'td';
    172242  $class = '';
    173   if ( $level > 0 )
    174   {
    175     $class = 'row'.$level;
    176   }
    177   else
    178   {
    179     $td = 'th';
    180   }
     243  if ( $level > 0 ) $class = 'row'.$level;
     244  else              $td = 'th';
    181245               
    182246  $query = 'SELECT id,name,dir,nb_images,status,rank,site_id,visible';
     
    201265    $vtp->setVar( $sub, 'cat.class', $class );
    202266    $vtp->setVar( $sub, 'cat.indent', $indent );
    203     if ( $row['name'] == '' )
    204     {
    205       $name = str_replace( '_', ' ', $row['dir'] );
     267    $vtp->setVar( $sub, 'cat.name', $row['name'] );
     268    if ( $row['dir'] != '' )
     269    {
     270      $vtp->addSession( $sub, 'storage' );
     271      $vtp->setVar( $sub, 'storage.dir', $row['dir'] );
     272      $vtp->closeSession( $sub, 'storage' );
     273      // category can't be deleted
     274      $vtp->addSession( $sub, 'no_delete' );
     275      $vtp->closeSession( $sub, 'no_delete' );
    206276    }
    207277    else
    208278    {
    209       $name = $row['name'];
    210     }
    211     $vtp->setVar( $sub, 'cat.name', $name );
    212     $vtp->setVar( $sub, 'cat.dir', $row['dir'] );
     279      $vtp->addSession( $sub, 'virtual' );
     280      $vtp->closeSession( $sub, 'virtual' );
     281      // category can be deleted
     282      $vtp->addSession( $sub, 'delete' );
     283      $url = './admin.php?page=cat_list&delete='.$row['id'];
     284      $vtp->setVar( $sub, 'delete.delete_url', add_session_id( $url ) );
     285      $vtp->closeSession( $sub, 'delete' );
     286    }
    213287    if ( $row['visible'] == 'false' or !$uppercat_visible )
    214288    {
     
    230304      $vtp->closeSession( $sub, 'up' );
    231305    }
    232     else
     306    else if ( $min_rank != $max_rank )
    233307    {
    234308      $vtp->addSession( $sub, 'no_up' );
     309      $url = add_session_id( './admin.php?page=cat_list&last='.$row['id']);
     310      $vtp->setVar( $sub, 'no_up.last_url', $url );
    235311      $vtp->closeSession( $sub, 'no_up' );
    236312    }
     
    242318      $vtp->closeSession( $sub, 'down' );
    243319    }
    244     else
     320    else if ( $min_rank != $max_rank )
    245321    {
    246322      $vtp->addSession( $sub, 'no_down' );
     323      $url = add_session_id('./admin.php?page=cat_list&first='.$row['id']);
     324      $vtp->setVar( $sub, 'no_down.first_url', $url );
    247325      $vtp->closeSession( $sub, 'no_down' );
    248326    }
     
    272350      $vtp->closeSession( $sub, 'no_permission' );
    273351    }
    274     if ( $row['site_id'] == 1 )
     352    // you can individually update a category only if it is on the main site
     353    // and if it's not a virtual category (a category is virtual if there is
     354    // no directory associated)
     355    if ( $row['site_id'] == 1 and $row['dir'] != '' )
    275356    {
    276357      $vtp->addSession( $sub, 'update' );
     
    292373}
    293374display_cat_manager( 'NULL', str_repeat( '&nbsp', 4 ), true, 0 );
     375// add a virtual category ?
     376$vtp->addSession( $sub, 'associate_cat' );
     377$vtp->setVar( $sub, 'associate_cat.value', '-1' );
     378$vtp->setVar( $sub, 'associate_cat.content', '' );
     379$vtp->closeSession( $sub, 'associate_cat' );
     380$page['plain_structure'] = get_plain_structure();
     381$structure = create_structure( '', array() );
     382display_categories( $structure, ' ' );
    294383//----------------------------------------------------------- sending html code
    295384$vtp->Parse( $handle , 'sub', $sub );
  • trunk/admin/cat_modify.php

    r57 r68  
    2424              'editcat_name','editcat_comment','editcat_status',
    2525              'editcat_visible','editcat_visible_info', 'submit',
    26               'editcat_uploadable' );
     26              'editcat_uploadable','cat_virtual','cat_parent' );
    2727templatize_array( $tpl, 'lang', $sub );
    2828//---------------------------------------------------------------- verification
     
    7272  $query.= ", status = '".$_POST['status']."'";
    7373  $query.= ", visible = '".$_POST['visible']."'";
    74   $query.= ", uploadable = '".$_POST['uploadable']."'";
     74
     75  if ( isset( $_POST['uploadable'] ) )
     76    $query.= ", uploadable = '".$_POST['uploadable']."'";
     77
     78  if ( isset( $_POST['associate'] ) )
     79  {
     80    $query.= ', id_uppercat = ';
     81    if ( $_POST['associate'] == -1 ) $query.= 'NULL';
     82    else                             $query.= $_POST['associate'];
     83  }
    7584  $query.= ' WHERE id = '.$_GET['cat'];
    7685  $query.= ';';
     86  echo $query;
    7787  mysql_query( $query );
    7888
     
    107117$vtp->setVar( $sub, 'cat:name', $cat_name );
    108118// cat dir
    109 $vtp->setVar( $sub, 'cat:dir', $row['dir'] );
     119if ( $row['dir'] != '' )
     120{
     121  $vtp->addSession( $sub, 'storage' );
     122  $vtp->setVar( $sub, 'storage.dir', $row['dir'] );
     123  $vtp->closeSession( $sub, 'storage' );
     124}
     125else
     126{
     127  $vtp->addSession( $sub, 'virtual' );
     128  $vtp->closeSession( $sub, 'virtual' );
     129}
    110130// remote site ?
    111131if ( $row['site_id'] != 1 )
     
    151171$vtp->closeSession( $sub, 'visible_option' );
    152172// uploadable : true or false
    153 if ( $conf['upload_available'] )
     173// a category can be uploadable if :
     174//  1. upload is authorized
     175//  2. category is not virtual
     176//  3. category is on the main site
     177if ( $conf['upload_available'] and $row['dir'] != '' and $row['site_id'] == 1 )
    154178{
    155179  $vtp->addSession( $sub, 'uploadable' );
     
    176200  $vtp->closeSession( $sub, 'uploadable' );
    177201}
     202// can the parent category be changed ? (is the category virtual ?)
     203if ( $row['dir'] == '' )
     204{
     205  $vtp->addSession( $sub, 'parent' );
     206  $vtp->addSession( $sub, 'associate_cat' );
     207  $vtp->setVar( $sub, 'associate_cat.value', '-1' );
     208  $vtp->setVar( $sub, 'associate_cat.content', '' );
     209  $vtp->closeSession( $sub, 'associate_cat' );
     210  $structure = create_structure( '', array() );
     211  display_categories( $structure, ' ', $row['id_uppercat'], $row['id'] );
     212  $vtp->closeSession( $sub, 'parent' );
     213}
    178214//----------------------------------------------------------- sending html code
    179215$vtp->Parse( $handle , 'sub', $sub );
  • trunk/admin/include/functions.php

    r61 r68  
    386386}
    387387
    388 function display_categories( $categories, $indent )
     388function display_categories( $categories, $indent,
     389                             $selected = -1, $forbidden = -1 )
    389390{
    390391  global $vtp,$sub;
    391392
    392393  foreach ( $categories as $category ) {
    393     $vtp->addSession( $sub, 'associate_cat' );
    394     $vtp->setVar( $sub, 'associate_cat.value',   $category['id'] );
    395     $content = $indent.'- '.$category['name'];
    396     $vtp->setVar( $sub, 'associate_cat.content', $content );
    397     $vtp->closeSession( $sub, 'associate_cat' );
    398     display_categories( $category['subcats'], $indent.str_repeat(' ',3) );
     394    if ( $category['id'] != $forbidden )
     395    {
     396      $vtp->addSession( $sub, 'associate_cat' );
     397      $vtp->setVar( $sub, 'associate_cat.value',   $category['id'] );
     398      $content = $indent.'- '.$category['name'];
     399      $vtp->setVar( $sub, 'associate_cat.content', $content );
     400      if ( $category['id'] == $selected )
     401        $vtp->setVar( $sub, 'associate_cat.selected', ' selected="selected"' );
     402      $vtp->closeSession( $sub, 'associate_cat' );
     403      display_categories( $category['subcats'], $indent.str_repeat(' ',3),
     404                          $selected, $forbidden );
     405    }
    399406  }
    400407}
  • trunk/language/francais.php

    r61 r68  
    493493  $lang['cat_permission'] = 'permissions';
    494494  $lang['cat_update'] = 'mis à jour';
     495  $lang['cat_add'] = 'Ajouter une catégorie virtuelle';
     496  $lang['cat_parent'] = 'catégorie parente';
     497  $lang['cat_error_name'] = 'Le nom d\'une catégorie ne doit pas être nul';
     498  $lang['cat_virtual'] = 'virtuelle';
     499  $lang['cat_first'] = 'Premier';
     500  $lang['cat_last'] = 'Dernier';
    495501  // end version 1.3
    496502
     
    498504  $lang['editcat_confirm'] = 'Informations enregistrées dans la base de données';
    499505  $lang['editcat_back'] = 'catégories';
    500   $lang['editcat_title1'] = 'Options pour la';
     506  $lang['editcat_title1'] = 'Options pour la catégorie';
    501507  $lang['editcat_name'] = 'Nom';
    502508  $lang['editcat_comment'] = 'Commentaire';
  • trunk/template/default/admin/cat_list.vtp

    r30 r68  
     1<!--VTP_errors-->
     2<div class="errors">
     3  <div class="errors_title">{#errors_title}</div>
     4  <ul>
     5    <!--VTP_li-->
     6    <li>{#content}</li>
     7    <!--/VTP_li-->
     8  </ul>
     9</div>
     10<!--/VTP_errors-->
    111<table style="width:100%;">
     12<tr>
     13  <td colspan="8" style="text-align:center;padding-top:10px;padding-bottom:10px;">
     14  <form action="" method="post">
     15    {#cat_add} <input type="text" name="virtual_name" />
     16    {#cat_parent}
     17    <select name="associate">
     18      <!--VTP_associate_cat-->
     19      <option value="{#value}">{#content}</option>
     20      <!--/VTP_associate_cat-->
     21    </select>
     22   <input type="submit" value="{#submit}" name="submit" />
     23  </form>
     24  </td>
     25</tr>
    226<!--VTP_cat-->
    327<tr>
    4   <{#td} style="width:40%;text-align:left;">
     28  <{#td} style="width:50%;text-align:left;">
    529    {#indent}<img src="../template/{#user_template}/admin/images/puce.gif" alt="&gt;" />
    6     &nbsp;{#name} [ dir : {#dir} ]
     30    &nbsp;{#name} [
     31    <!--VTP_storage-->
     32    dir : {#dir}
     33    <!--/VTP_storage-->
     34    <!--VTP_virtual-->
     35    <span style="color:blue;">{#cat_virtual}</span>
     36    <!--/VTP_virtual-->
     37    ]
    738    <span style="color:red;font-weight:normal;"> {#invisible} <span style="font-weight:bold;">{#private}</span></span>
    839  </{#td}>
    9   <{#td} style="text-align:center;">
     40  <{#td} class="{#class}"
     41         style="width:1px;white-space:nowrap;text-align:center;">
     42    <!--VTP_up-->
     43    <a href="{#up_url}"><img src="../template/{#user_template}/admin/images/arrow_up.gif" alt="{#cat_up}" title="{#cat_up}" style="border:none;" /></a>
     44    <!--/VTP_up-->
     45    <!--VTP_no_up-->
     46    <a href="{#last_url}"><img src="../template/{#user_template}/admin/images/arrow_last.gif" alt="{#cat_last}" title="{#cat_last}" style="border:none;" /></a>
     47    <!--/VTP_no_up-->
     48  </{#td}>
     49  <{#td} class="{#class}"
     50         style="width:1px;white-space:nowrap;text-align:center;">
     51    <!--VTP_down-->
     52    <a href="{#down_url}"><img src="../template/{#user_template}/admin/images/arrow_down.gif" alt="{#cat_down}" title="{#cat_down}" style="border:none;" /></a>
     53    <!--/VTP_down-->
     54    <!--VTP_no_down-->
     55    <a href="{#first_url}"><img src="../template/{#user_template}/admin/images/arrow_first.gif" alt="{#cat_first}" title="{#cat_first}" style="border:none;" /></a>
     56    <!--/VTP_no_down-->
     57  </{#td}>
     58  <{#td} class="{#class}" style="width:1px;text-align:center;">
    1059    <div style="margin-left:3px;margin-right:3px;">{#nb_picture}</div>
    1160  </{#td}>
     
    1362         style="width:10%;white-space:nowrap;text-align:center;">
    1463    <a href="{#edit_url}">{#cat_edit}</a>
    15   </{#td}>
    16   <{#td} class="{#class}"
    17          style="width:10%;white-space:nowrap;text-align:center;">
    18     <!--VTP_up-->
    19     <a href="{#up_url}">{#cat_up}</a>
    20     <!--/VTP_up-->
    21     <!--VTP_no_up-->
    22     <span style="color:darkgray;">{#cat_up}</span>
    23     <!--/VTP_no_up-->
    24   </{#td}>
    25   <{#td} class="{#class}"
    26          style="width:10%;white-space:nowrap;text-align:center;">
    27     <!--VTP_down-->
    28     <a href="{#down_url}">{#cat_down}</a>
    29     <!--/VTP_down-->
    30     <!--VTP_no_down-->
    31     <span style="color:darkgray;">{#cat_down}</span>
    32     <!--/VTP_no_down-->
    3364  </{#td}>
    3465  <{#td} class="{#class}"
     
    5990    <!--/VTP_no_update-->
    6091  </{#td}>
     92  <{#td} class="{#class}"
     93         style="width:10%;white-space:nowrap;text-align:center;">
     94    <!--VTP_delete-->
     95    <a href="{#delete_url}">{#delete}</a>
     96    <!--/VTP_delete-->
     97    <!--VTP_no_delete-->
     98    <span style="color:darkgray;">{#delete}</span>
     99    <!--/VTP_no_delete-->
     100  </{#td}>
    61101<tr>
    62102<!--/VTP_cat-->
  • trunk/template/default/admin/cat_modify.vtp

    r38 r68  
    66  <table style="width:100%;">
    77    <tr>
    8       <th colspan="2">{#editcat_title1} "{#cat:name}" [ {#cat:dir} ]</th>
     8      <th colspan="2">{#editcat_title1} "{#cat:name}" [
     9        <!--VTP_storage-->
     10        dir : {#dir}
     11        <!--/VTP_storage-->
     12        <!--VTP_virtual-->
     13        <span style="color:blue;">{#cat_virtual}</span>
     14        <!--/VTP_virtual-->
     15        ]
     16      </th>
    917    </tr>
    1018    <!--VTP_server-->
     
    5361    </tr>
    5462    <!--/VTP_uploadable-->
     63    <!--VTP_parent-->
     64    <tr>
     65      <td>{#cat_parent}</td>
     66      <td class="row2">
     67        <select name="associate">
     68          <!--VTP_associate_cat-->
     69          <option value="{#value}"{#selected}>{#content}</option>
     70          <!--/VTP_associate_cat-->
     71        </select>
     72      </td>
     73    </tr>
     74    <!--/VTP_parent-->
    5575    <tr>
    5676      <td colspan="2">&nbsp;</td>
Note: See TracChangeset for help on using the changeset viewer.