<?php
/*
Copyright (C) 2008 by oscim   Project lossim  [ 15.09.2009, 09:17:59] @oscim
// kate: replace-trailing-space-save true; space-indent on; indent-width 2; mixedindent off; indent-mode cstyle; word-wrap-marker-color #41C2A4
ENCODE UTF-8
*/
/**
  Creat / Edition d'un post
  si new, un fichier temporaire bak_tmp.xml est créer, celui ci est
*/
  error_reporting(E_ALL);
//! prepa

  $file= (isset($_GET['file']))  ? trim($_GET['file']) : '';
  $file_rep= (isset($_GET['file_rep'])) ? trim($_GET['file_rep']) : '';
//! Pas de rep ni file , sortie
  if(empty($file) && empty($file_rep) )  redirect('admin.php');

//! ACTION
 $action=(isset($post['action']) ) ?$post['action'] : 'new';

//! var init
  $_POST['desc_page']= (isset($post['desc_page'])) ? $post['desc_page'] :'';
  $post['etat_page']= (isset($post['etat_page'])) ? trim($post['etat_page']) :'';
  $post['page_home']= (isset($post['page_home'])) ? $post['page_home'] :'';
  $post['fixe_mod'] = (isset($post['fixe_mod'])) ? $post['fixe_mod'] : '';
  $path_rep=ADD_PATH_ADMIN.REP_DATA;


/// obj  posts
  $cstr->_add_class('i_db_link',_BO_CLASS .'class.i_db_link.php');
  $cstr->_add_class('db_posts',_BO_CLASS .'class.db_posts.php',$file);
  $cstr->_add_class('db_rubrique',_BO_CLASS .'class.db_rubrique.php',$file);
  $the_post=$cstr->_call('db_posts','the_post');
  $cstr->_add_class('aff_articles',_BO_CLASS .'class.aff_articles.php');
  $cstr->_add_class('doc_name',_BO_CLASS .'class.doc_name.php');

  switch($action) {
  //! DEB ENREGITREMENT
    case 'del':
      if  (tep_not_null($file))  {
        $cstr->doc_name->init($the_post);
        $cstr->_call('db_posts','del_post', $file);

        redirect(_FILENAME_ADMIN);
      }
    break;
  //! FIN ENREGITREMENT

  //! DEB DRAW
    case 'up':
    case 'edit':
      if(isset($_POST['confirm']) || isset($_POST['confirm_close'])){
        $cstr->_call('doc_name','init',$post);
        $post['new_name']=$cstr->_call('doc_name','New_name');
        $new_path_file = $cstr->_call('db_posts','up_post',$post);

        if (test_bool($new_path_file)){
          //! recalcul des element apres enregsitrement si pas redirect
          $cstr->_call('db_posts','init_post',$file);
          $the_post=$cstr->_call('db_posts','the_post');
        } else {
          if (!isset($_POST['confirm_close'])) redirect(_FILENAME_MODIFIER_UN_FICHIER."?file=".ADD_PATH_ADMIN.REP_DATA.$new_path_file."&fixe_mod=".$_POST['fixe_mod'].'&action=edit');
          else redirect(_FILENAME_ADMIN);
          exit;
        }
      }

      $articles=$cstr->_call('aff_articles','the_tab_content');
      $post['tpage']=(isset($the_post['title_'.$the_post['lang']])) ? $the_post['title_'.$the_post['lang']] : $the_post['titre'];
      $post['link_public']=URL_DU_SITE.'?'.$the_post['lang'].'/'.$the_post['rub'].$the_post['nom_ss_ext'].'.html';

      $post['rub'] =  $the_post['rub'] ;
      $post['chemin']=$post['rub'];
      $post['chemin'].=clean_for_name_files($post['tpage']);

    break;

    case 'new':
    default:
      $the_post=$cstr->_call('doc_name','init',array('titre' => 'bak_test','etat_page'=>'I','file_rep'=>$file_rep, 'choose_lg'=>@$post['choose_lg']) );
      $cstr->_call('db_posts','add_post');
      $path=( !preg_match( "/^.*\/$/", $the_post->new_chemin ) ) ?$the_post->new_chemin.'/' : $the_post->new_chemin;
      redirect(_FILENAME_MODIFIER_UN_FICHIER."?file=".$path.$the_post->bak_name.'.'.$the_post->ext."&etat_page=I&fixe_mod=".$post['fixe_mod'].'&action=edit');
      exit;
  }

//! END ENREGITREMENT
?>