WebCalendar PHP Cross Reference Groupware Applications

Source: /category_handler.php - 135 lines - 4430 bytes - Summary - Text - Print

   1  <?php
   2  /* $Id: category_handler.php,v 1.33.2.6 2012/02/28 02:54:55 cknudsen Exp $ */
   3  include_once  'includes/init.php';
   4  require_valide_referring_url ();
   5  
   6  $icon_max_size = '3000';
   7  $icon_path = 'icons/';
   8  
   9  /* Rename any icons associated with this cat_id. */
  10  function renameIcon ( $id ) {
  11    global $icon_path;
  12    $bakIcon = $catIcon = $icon_path . 'cat-';
  13    $bakIcon .= date ( 'YmdHis' ) . '.gif';
  14    $catIcon .= $id . '.gif';
  15    if ( file_exists ( $catIcon ) )
  16      rename ( $catIcon, $bakIcon );
  17  }
  18  
  19  // Does the category belong to the user?
  20  $is_my_event = false;
  21  $id = getValue ( 'id' );
  22  $catname = getValue ( 'catname' );
  23  $catcolor = getValue ( 'catcolor' );
  24  $isglobal = getValue ( 'isglobal' );
  25  $delIcon = getPostValue ( 'delIcon' );
  26  if ( empty ( $id ) )
  27    $is_my_event = true; // New event.
  28  else {
  29    $res = dbi_execute ( 'SELECT cat_id, cat_owner FROM webcal_categories
  30      WHERE cat_id = ?', array ( $id ) );
  31    if ( $res ) {
  32      $row = dbi_fetch_row ( $res );
  33  
  34      $is_my_event = ( $row[0] == $id && $row[1] == $login ||
  35        ( empty ( $row[1] ) && $is_admin ) );
  36  
  37      dbi_free_result ( $res );
  38    } else
  39      $error = db_error ();
  40  }
  41  
  42  if ( ! empty ( $_FILES['FileName'] ) )
  43    $file = $_FILES['FileName'];
  44  
  45  // Make sure we clear $file if no file was upoaded.
  46  if ( ! empty ( $file['tmp_name'] ) && $file['tmp_name'] == 'none' )
  47    $file = '';
  48  
  49  if ( ! $is_my_event )
  50    $error = print_not_auth (5);
  51  
  52  $delete = getPostValue ( 'delete' );
  53  if ( empty ( $error ) && ! empty ( $delete ) ) {
  54    // Delete this category.
  55    if ( ! dbi_execute ( 'DELETE FROM webcal_categories
  56      WHERE cat_id = ? AND ( cat_owner = ?'
  57         . ( $is_admin ? ' OR cat_owner IS NULL )' : ' )' ),
  58          array ( $id, $login ) ) ) {
  59      $error = db_error ();
  60    }
  61  
  62    if ( ! dbi_execute ( 'DELETE FROM webcal_entry_categories
  63      WHERE cat_id = ? AND ( cat_owner = ?'
  64         . ( $is_admin ? ' OR cat_owner IS NULL )' : ' )' ),
  65          array ( $id, $login ) ) ) {
  66      $error = db_error ();
  67    }
  68    // Rename any icons associated with this cat_id.
  69    renameIcon ( $id );
  70  } else if ( empty ( $error ) && empty ( $catname ) ) {
  71    $error = translate ( 'Category name is required' );
  72  } else if ( empty ( $error ) ) {
  73    if ( ! empty ( $id ) ) {
  74      # Update (don't let them change global status).
  75      if ( ! dbi_execute ( 'UPDATE webcal_categories
  76        SET cat_name = ?, cat_color = ? WHERE cat_id = ?',
  77          array ( $catname, $catcolor, $id ) ) )
  78        $error = db_error ();
  79  
  80      if ( ! empty ( $delIcon ) && $delIcon == 'Y' )
  81        renameIcon ( $id );
  82    } else {
  83      // Add new category.
  84      // Get new id.
  85      $res = dbi_execute ( 'SELECT MAX( cat_id ) FROM webcal_categories' );
  86      if ( $res ) {
  87        $row = dbi_fetch_row ( $res );
  88        $id = $row[0] + 1;
  89        dbi_free_result ( $res );
  90        $catowner = ( $is_admin
  91          ? ( $isglobal == 'Y' ? null : $login )
  92          : $login );
  93  
  94        if ( ! dbi_execute ( 'INSERT INTO webcal_categories ( cat_id, cat_owner,
  95          cat_name, cat_color ) VALUES ( ?, ?, ?, ? )',
  96            array ( $id, $catowner, $catname, $catcolor ) ) )
  97          $error = db_error ();
  98      } else
  99        $error = db_error ();
 100    }
 101    if ( empty ( $delIcon ) && is_dir( $icon_path ) && ( !
 102          empty ( $ENABLE_ICON_UPLOADS ) && $ENABLE_ICON_UPLOADS == 'Y' ||
 103          $is_admin ) ) {
 104      // Save icon if uploaded.
 105      if ( ! empty ( $file['tmp_name'] ) ) {
 106        if ( $file['type'] == 'image/gif' && $file['size'] <= $icon_max_size ) {
 107          // $icon_props = getimagesize ( $file['tmp_name']  );
 108          // print_r ($icon_props );
 109          $path_parts = pathinfo ( $_SERVER['SCRIPT_FILENAME'] );
 110          $fullIcon = $path_parts['dirname'] . '/'
 111           . $icon_path . 'cat-' . $id . '.gif';
 112          renameIcon ( $id );
 113          $file_result = move_uploaded_file ( $file['tmp_name'], $fullIcon );
 114          // echo "Upload Result:" . $file_result;
 115        } else
 116        if ( $file['size'] > $icon_max_size )
 117          $error = translate ( 'File size exceeds maximum.' );
 118        else
 119        if ( $file['type'] != 'image/gif' )
 120          $error = translate ( 'File is not a gif image.' );
 121      }
 122      // Copy icon if local file specified.
 123      $urlname = getPostvalue ( 'urlname' );
 124      if ( ! empty ( $urlname ) && file_exists ( $icon_path . $urlname ) )
 125        copy ( $icon_path . $urlname, $icon_path . 'cat-' . $id . '.gif' );
 126    }
 127  }
 128  
 129  if ( empty ( $error ) )
 130    do_redirect ( 'category.php' );
 131  
 132  print_header ();
 133  echo print_error ( $error ) . print_trailer ();
 134  
 135  ?>

title

Description

title

Description

title

Description

title

title

Body