<?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
*/


## Amelioration pour gestion par ajax
function navi_plus ($file_rep,$nave ,$file,$url_form,$url_navi,$lang){
  $format_ajax="upload_ajax('%1\$s','%2\$s','%3\$s','%4\$s'); ";
  if (!empty($nave))  $lang=$nave;
  if (!empty($file))  $url_lang=$file;
  elseif (!empty($file_rep))$url_lang=$file_rep;
  else  $url_lang='';
  $lang_view=charg_lang($lang,$url_lang);
  $nave=ADD_PATH_ADMIN.REP_DATA.$lang_view;
  if( !preg_match( "/^.*\/$/", $nave ) ) $nave .= '/';
  define('LEFILEEDIT', $file);
  tep_form ($url_form,'',"&lang=".$lang,"nav","POST",true," onsubmit='return checkForm(this)'" );

          print "<h3>".NAVI_CHOIX_LG_DOCUMENT."</h3>"."<select name='nav' OnChange=\"";
                  printf($format_ajax,'block_sommaire_gauche','include/lib/lib.creer_une_page.php','navi_plus'," \'"."\',\''+this.value+'\',\'".$file."\',\'modifier_un_fichier.php\',\'modifier_un_fichier.php\',\'".$lang_view."\' ");
                  print " \">";
                  $lg=appel_lang();
                          print "<option value='".LANG."'>Par defaut: ".$lg[LANG]['txt']."</option>\n";
                          while ($r=each($lg))
                                  if ($r['key']==$lang_view) {
                                          print "<option value='".$r['key']."' selected>".$r['value']['txt']."</option>\n";
                                          tep_mkdir(ADD_PATH_ADMIN.REP_DATA.$r['key']);
                                  }
                                  else print "<option value='".$r['key']."'>".$r['value']['txt']."</option>\n";
          print "</select>";
  print "</form>";
  print "<h3>".NAVI_DOCUMENTS."</h3>";
  print NewFct('liste_navi','',$nave, $url_navi,"",true);
}

## Remplacement des caratéres accentués et tous caratéres non imprimables
function clean_accents ($content){
  $content = strtolower($content);
  $content = stripslashes($content);
  $array_1 = array("!","?",";","&","\"","'"," - ","^","\'","/","ç","é","è","ê","ë","à","â","ù","û","ô","ö","î","ï","Ç","É","È","Ê","Ë","À","Â","Ù","Û","Ô","Ö","Î","Ï");
  $array_2 = array("","","","-","-","","-","+","'","-","c","e","e","e","e","a","a","u","u","o","o","i","i","c","e","e","e","e","a","a","u","u","o","o","i","i");
  $content = str_replace($array_1, $array_2, $content);
  return $content;
}

function mode_editions ($fixe_mod){
  $j= "<option value='%1\$s' %2\$s >%3\$s</option>";
  $z= "<select name='fixe_mod' class=\"input_100p\" onchange=\"document.post.submit();\">\n";
          if (empty($fixe_mod)) $fixe_mod=_USER_PERSO__PREF_MOD_EDIT;
          if (!empty($fixe_mod)) {
                  if (trim($fixe_mod) =="bbcode") $z.=sprintf($j,'bbcode','selected',MODE_EDITIONS_DEFAULT);
                  elseif (trim($fixe_mod) =="openwysing") $z.=sprintf($j,'openwysing','selected',MODE_EDITIONS_AVANCEE);
                  elseif (test_const('PX_CONFIG_MODULE_TINYMCE') && trim($fixe_mod) =="tinymce") $z.=sprintf($j,'tinymce','selected','tinymce');
          }
          $z.=sprintf($j,'bbcode','',MODE_EDITIONS_DEFAULT);
          $z.=sprintf($j,'openwysing','','openwysing');
          if (test_const('PX_CONFIG_MODULE_TINYMCE')) $z.=sprintf($j,'tinymce','','tinymce');
          if (test_const('PX_CONFIG_MODULE_FCKEDITOR')) $z.=sprintf($j,'fckeditor','','fckeditor');
  $z.= "</select>\n";
  return $z;
}

function select_editeur_d_edition($mode=''){
  if (empty($mode)) return _USER_PERSO__PREF_MOD_EDIT;
  else return $mode;
}

// Ce chargeur permet de slectionner le choix entre le mode dd'edition bbcode, ou openwysing
function charg_editeur_d_edition($mode='',$header=false){

        $h=array('bbcode'=>'admin/ext/bbcode/bbcode.js','openwysing'=>'admin/ext/openwysing/wysiwyg.js' );
        if (test_const('PX_CONFIG_MODULE_TINYMCE'))$h['tinymce']=_TINYMCE_LIB_JS;
        if (test_const('PX_CONFIG_MODULE_FCKEDITOR'))$h['fckeditor']="ext/fckeditor/fckeditor.php";
        $mode_actif=select_editeur_d_edition($mode);
        if ($header) {
                if  ( $mode_actif== 'openwysing') {
                        include_file (_SCRIPTACULOUS_LIB_SCRIPTACULOUS);
                        include_file (_LIGHTWINDOW_LIB_LIGHTWINDOW);
                        include_file (_LIGHTWINDOW_CSS_LIGHTWINDOW);

                }elseif  ($mode_actif == 'tinymce') { //language : "'.LANG_POST.'",
                  $nom=NewFct('cstr_liste','page_template/',"") ;

                  include_file ($h[$mode_actif]);
                        print '<script type="text/javascript" src="'.URL_DU_SITE.'ext/tinymce/plugins/tinybrowser/tb_tinymce.js.php"></script>';
                        print '<script type="text/javascript" language="javascript1.2">'
                                .'tinyMCE.init({'
                                        .'mode : "textareas",'
                                        .'theme : "advanced",'
                                        .'language : "en",'
                                        .'plugins : "paste,cleanup,iespell,advlink,advimage, advhr,media,tinybrowser,xhtmlxtras,template,'./*inlinepopups,'contextmenu,nonbreaking,noneditable,pagebreak,,ibrowser,imagemanager,filemanager,'.*/'fullscreen",'

                                        .'theme_advanced_buttons1 : ",bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,styleselect,formatselect,fontselect,fontsizeselect",'
                                        .'theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,media,advimage,tinyBrowser,filemanager, cleanup,forecolor,backcolor,template,",'
                                        .'theme_advanced_buttons3 : "removeformat,visualaid,|,sub,sup,|,charmap,iespell,advhr,pagebreak,noneditable, |,fullscreen,help,code",'

                                        .'theme_advanced_toolbar_location : "top",'
                                        .'theme_advanced_toolbar_align : "left",'
                                        .'theme_advanced_statusbar_location : "bottom",'
                                        .'theme_advanced_resizing : true,'

                                        .'file_browser_callback : "tinyBrowser",'

                                        .'content_css : "'.URL_DU_SITE.'template/'.NOM_DU_THEME.'/'.NOM_STYLES_CSS.'.css",'

                                        .'apply_source_formatting : false,'
                                        .'entity_encoding : "raw",'
                                        .'verify_html : false,'
                                        .'paste_retain_style_properties:true,'
                                        .'paste_remove_spans:true,'
                                        .'paste_auto_cleanup_on_paste : true,'
                                        .'paste_remove_styles_if_webkit: true,'
                                        .'paste_preprocess : function(pl, o) {
                                                 alert(o.content);
                                        },'
                                        .'paste_postprocess : function(pl, o) {
                                                alert(o.node.innerHTML);
                                        },'
//                                      .'force_br_newlines : true,'

                                        .'template_templates : [
                                                ';
                                                foreach($nom as $f)
                                                  print ' {
                                                        title : "'.substr($f,0,strlen($f)-4).'",
                                                        src : "page_template/'.$f.'",
                                                        description : ""
                                                        },';
                          print '                 ]'

                                        .'});'
                                .'</script>';


                } else
                        include_file ($h[$mode_actif]);

        }else {
                if  ( $mode_actif== 'openwysing') {
                        include('ext/openwysing/openwysing_ext.js');
                        include_file ($h[$mode_actif]);
                        print '<script type="text/javascript" language="javascript1.2">'
                                .'generate_wysiwyg(\'message\');'
                                .'</script>';

                }elseif  ($mode_actif == 'fckeditor') {

                        $oFCKeditor = new FCKeditor('message') ;
                        $oFCKeditor->BasePath = ADD_PATH_ADMIN.'ext/fckeditor/' ;       // '/fckeditor/' is the default value.
                        $oFCKeditor->Config['AutoDetectLanguage']       = false ;
                        $oFCKeditor->Config['DefaultLanguage']          = LANG_POST ;
//                      $oFCKeditor->Value              = '<p>This is some <strong>sample text</strong>. You are using <a href="http://www.fckeditor.net/">FCKeditor</a>.</p>' ;
                        $oFCKeditor->Create() ;
//                      print '<script> document.getElementById(\'message\').style="visibility=hidden";</script>';
                }
        }

        print '<script language="JavaScript" type="text/javascript" src="include/js/calendar.js"></script>';
        if (!defined('SELECTED_MODE_EDIT')) define("SELECTED_MODE_EDIT",$mode);
        return $mode;
}




?>