<?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
*/
/**
  Suivi et synchro de la base index des files

  @package lossim <web http://www.lossim.org>
  @author oscim <mail dom@oscim.fr > <web http://www.oscim.fr>
  @class files

*/
error_reporting(E_ALL);
class i_db_link extends db{

  /**

  */
  function i_db_link(){
    global $cstr;
    $i_links=$this->add_tbl_php(ADD_PATH_ADMIN.TBL_INDEX_LINKS_INC,'i_links');
    $this->i_links = (isset($i_links) && is_array($i_links))? $i_links: array();

    $this->modele_db=array(
                'href'=> 'text' ,
                'etat'=> 'boolean',
//                 'date_created'=> 'date' ,
                'date_modified'=> 'date' ,
                'date_publi'=> 'date' ,
                'date_retrait'=> 'date' ,
            /** Colonne utiliser suffixer par la lang titre_fr ne preciser que le prefix */
                'lang'=> array(
                      'title' => 'text'
                       )
               );
  }

  /**
    recuperation des elements de la key
    @param
      @p array db i_link
  */
  /*public*/ function db_i_link($key=''){
    if (isset($this->i_links[$key])) return $this->i_links[$key];
    return $this->i_links;
  }


  /**
    Test la key
    @param
      @p string  la clef (md5 32 carat)
    @return bollean
  */
  /*private*/ function test_key_i_link($key_cat=''){
    if (tep_not_null($key_cat) && isset($this->i_links[(string)$key_cat])) return true;
    return false;
  }


  /**
  exe synchro db links
  Si arg key, prend le post en cours sinon prend les key fournis
  @param
    @p obj cstr
    @a string md5 path/name_ss_ext new
    @a string md5 path/name_ss_ext bak
    @a array tableau de key/value à inserer ds db
    @a array Modele db pour remplacer le modele par defaut
  */
  /*public*/ function _c_db_synch($new_key, $bak_key,$darr,$modele_db='',$lang=LANG_POST){
      error_reporting(E_ALL);
    if (empty($new_key) || empty($bak_key))  return false;

    if (is_array($modele_db)) $this->modele_db=$modele_db;

    foreach($darr as $k=>$v){
       if ($k =='lang') $this->add_array($this->prepa_lang($v));
       else $this->add_item($k,$v);

    }
    $this->add_item('date_modified', date("m-d-Y"));
    $this->add_item('author', value_in_session('login_utilisateur'));

    $tbl_actu=$this->db_i_link($bak_key);

    if (!isset($this->item['date_created']) && ( (!isset($tbl_actu['date_created']) || empty($tbl_actu['date_created'])) ) ) $this->add_item('date_created', date("m-d-Y",@filemtime($bak_key)));

    $this->sync_db($new_key,$bak_key,$this->test_key_i_link($new_key),$tbl_actu, TBL_INDEX_LINKS_INC,$lang);

    return true;
  }


  /**
    Suppress du post en cours
    @param
      @a string key a supp
  */
  /*public*/ function c_db_del($key){
    return $this->del_item_db($key);
  }


  /**
    Supp d'une entrée complete ds db
    @a string key a supp (hash md5)
  */
  /*private*/ function del_item_db($key){
    $query =" DELETE FROM  ".TBL_INDEX_LINKS_INC." WHERE id  = '".$key."' ";
    return sql ('',ADD_PATH_ADMIN.TBL_INDEX_LINKS_INC,'i_links',$query,'');
  }


  /*public*/ function debugg(){
      print_r($this);
  }
}
?>