[ Index ]
 

Code source de WebCalendar 1.0.5

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables | Statistiques

title

Body

[fermer]

/ -> category_handler.php (source)

   1  <?php
   2  include_once  'includes/init.php';
   3  
   4  // does the category belong to the user?
   5  $is_my_event = false;
   6  if ( empty ( $id ) ) {
   7    $is_my_event = true; // new event
   8  } else {
   9    $res = dbi_query ( "SELECT cat_id, cat_owner FROM webcal_categories " .
  10      "WHERE cat_id = $id" );
  11    if ( $res ) {
  12      $row = dbi_fetch_row ( $res );
  13      if ( $row[0] == $id && $row[1] == $login )
  14        $is_my_event = true;
  15      else if ( $row[0] == $id && empty ( $row[1] ) && $is_admin )
  16        $is_my_event = true; // global category
  17      dbi_free_result ( $res );
  18    } else {
  19      $error = translate("Database error") . ": " . dbi_error ();
  20    }
  21  }
  22  
  23  if ( ! $is_my_event )
  24    $error = translate ( "You are not authorized" ) . ".";
  25  
  26  
  27  if ( empty ( $error ) &&
  28    ( $action == "Delete" || $action == translate ("Delete") ) ) {
  29    // delete this category
  30    if ( $is_admin ) {
  31      if ( ! dbi_query ( "DELETE FROM webcal_categories " .
  32        "WHERE cat_id = $id AND " .
  33        "( cat_owner = '$login' OR cat_owner IS NULL )" ) )
  34        $error = translate ("Database error") . ": " . dbi_error();
  35    } else {
  36      if ( ! dbi_query ( "DELETE FROM webcal_categories " .
  37        "WHERE cat_id = $id AND cat_owner = '$login'" ) )
  38        $error = translate ("Database error") . ": " . dbi_error();
  39    }
  40        
  41    // Set any events in this category to NULL
  42    if ( ! dbi_query ( "UPDATE webcal_entry_user SET cal_category = NULL " .
  43      "WHERE cal_category = $id" ) )
  44      $error = translate ("Database error") . ": " . dbi_error();
  45  } else if ( empty ( $error ) ) {
  46    if ( ! empty ( $id ) ) {
  47      # update (don't let them change global status)
  48      $sql = "UPDATE webcal_categories SET cat_name = '$catname' " .
  49        "WHERE cat_id = $id";
  50      if ( ! dbi_query ( $sql ) ) {
  51        $error = translate ("Database error") . ": " . dbi_error();
  52      }
  53    } else {
  54      // add new category
  55      // get new id
  56      $res = dbi_query ( "SELECT MAX(cat_id) FROM webcal_categories" );
  57      if ( $res ) {
  58        $row = dbi_fetch_row ( $res );
  59        $id = $row[0] + 1;
  60        dbi_free_result ( $res );
  61        if ( $is_admin ) {
  62          if ( $isglobal == "Y" )
  63            $catowner = "NULL";
  64          else
  65            $catowner = "'$login'";
  66        } else
  67          $catowner = "'$login'";
  68        $sql = "INSERT INTO webcal_categories " .
  69          "( cat_id, cat_owner, cat_name ) " .
  70          "VALUES ( $id, $catowner, '$catname' )";
  71        if ( ! dbi_query ( $sql ) ) {
  72          $error = translate ("Database error") . ": " . dbi_error();
  73        }
  74      } else {
  75        $error = translate ("Database error") . ": " . dbi_error();
  76      }
  77    }
  78  }
  79  if ( empty ( $error ) )
  80    do_redirect ( "category.php" );
  81  
  82  print_header();
  83  ?>
  84  <h2><?php etranslate("Error")?></h2>
  85  
  86  <blockquote>
  87  <?php echo $error; ?>
  88  </blockquote>
  89  
  90  <?php print_trailer(); ?>
  91  </body>
  92  </html>


Généré le : Fri Nov 30 19:09:19 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics