/**
 * Plugin smarty type fonction
 * Purpose:  send form by javascript to given href.
 *
 * Input:    href     = (required)  where to send the form
 *           form     = (required) id of the form
 *           assign   = (optional) name of the template variable we'll assign
 *                      the output to instead of displaying it directly
 *
 * Examples:
 */
function smarty_function_jssubmitform($params, &$this)
{
    if (!isset($params['href'])) {
        $this->_trigger_fatal_error("[smarty jssubmitform] Missing href parameter");
        return;
    }
    if (!isset($params['form'])) {
        $this->_trigger_fatal_error("[smarty jssubmitform] Missing form parameter");
        return;
    }
    static $_init = false;
    if (!$_init) {
        $jsCode = 'function doSubmitForm (pUrl, formId) {
                     var myForm = document.getElementById(formId);
                     myForm.action = pUrl;
                     myForm.submit ();
                     return false;
                  }';
        CopixHtmlHeader::addJsCode($jsCode);
        $_init = true;
    }
    $toReturn = 'return doSubmitForm(\'' . $params['href'] . '\', \'' . $params['form'] . '\')';
    if (isset($params['assign'])) {
        $this->assign($params['assign'], $toReturn);
        return '';
    } else {
        return $toReturn;
    }
}
function smarty_function_htmlarea($params, &$smarty)
{
    static $_init = false;
    extract($params);
    //check the initialisation
    if (!$_init) {
        CopixHtmlHeader::addJsCode('_editor_url = "' . CopixUrl::get() . 'js/htmlarea/";');
        //path of the library
        if (empty($path)) {
            $path = CopixUrl::get() . 'js/htmlarea/';
            //default path under CopiX
        }
        CopixHTMLHeader::addJSLink($path . 'htmlarea.js');
        CopixHTMLHeader::addJSLink($path . 'dialog.js');
        if (empty($lang)) {
            $lang = CopixI18N::getLang();
        }
        CopixHTMLHeader::addJSLink($path . 'lang/' . $lang . '.js');
        CopixHTMLHeader::addCSSLink($path . 'htmlarea.css');
        CopixHTMLHeader::addJSLink($path . 'popupwin.js');
        CopixHTMLHeader::addJSCode('
                HTMLArea.loadPlugin("TableOperations");
                HTMLArea.loadPlugin("InsertAnchor");
                HTMLArea.loadPlugin("TableToggleBorder");
                HTMLArea.loadPlugin("AstonTools");
                HTMLArea.loadPlugin("ContextMenu");
                ');
        $_init = true;
    }
    if (empty($content)) {
        $content = '';
    }
    //name of the textarea.
    if (empty($name)) {
        $smarty->trigger_error('htmlarea: missing name parameter');
    } else {
        //       CopixHTMLHeader::addOthers ($script);
        if (!$width) {
            $width = 500;
        }
        if (!$height) {
            $height = 500;
        }
        $out = '<textarea id="' . $name . '" name="' . $name . '" style="width: ' . $width . 'px; height:' . $height . 'px;" >' . $content . '</textarea>';
        $out .= '<script type="text/javascript" defer="1">
       var editor' . $name . ' = null;
       editor' . $name . ' = new HTMLArea("' . $name . '");
       editor' . $name . '.registerPlugin("TableOperations");
       editor' . $name . '.registerPlugin("TableToggleBorder");
       editor' . $name . '.registerPlugin("InsertAnchor");
       editor' . $name . '.registerPlugin("AstonTools");
       editor' . $name . '.registerPlugin("ContextMenu");
       editor' . $name . '.config.pageStyle = "@import url(\\"' . CopixUrl::get() . 'styles/styles_copix.css\\");";
       editor' . $name . '.generate ();
       </script>';
    }
    return $out;
}
 public function process($params)
 {
     static $_init = false;
     if (!isset($params['href'])) {
         throw new CopixTemplateTagException("[smarty jssubmitform] Missing href parameter");
         return;
     }
     if (!isset($params['form'])) {
         throw new CopixTemplateTagException("[smarty jssubmitform] Missing form parameter");
         return;
     }
     if (!$_init) {
         $jsCode = 'function doSubmitForm (pUrl, formId) {
                  var myForm = document.getElementById(formId);
                  myForm.action = pUrl;
                  myForm.submit ();
                  return false;
               }';
         CopixHtmlHeader::addJsCode($jsCode);
         $_init = true;
     }
     $toReturn = 'return doSubmitForm(\'' . $params['href'] . '\', \'' . $params['form'] . '\')';
     return $toReturn;
 }
/**
 * Smarty {popupinformation}{/popupinformation} block plugin
 *
 * Type:     block function<br>
 * Name:     popupinformation<br>
 * Purpose:  Add div wich display when mouse is over img<br>
 * @param array
 * <pre>
 * Params:   img: string
 * Params:   text: string
 * Params:   divclass: (optional)string, css class
 * Params:   displayimg: (optional, default true)boolean, display img ?
 * Params:   displaytext: (optional, default false) boolean , displaty text after img ?
 * Params:   assign :(optional) name of the template variable we'll assign
 *                      the output to instead of displaying it directly
 * </pre>
 * @param string contents of the block
 * @param Smarty clever simulation of a method
 * @return string string $content re-formatted
 */
function smarty_block_popupinformation($params, $content, &$smarty)
{
    static $_init = false;
    if (!$_init) {
        $jsCode = 'function displayPopupInformation(id) {
                  document.getElementById(id).style.visibility = \'visible\';
               }
               function hidePopupInformation(id) {
                  document.getElementById(id).style.visibility = \'hidden\';
               }
               function toggleDisplayPopupInformation(id) {
                  if (document.getElementById(id).style.visibility==\'hidden\') {
                     document.getElementById(id).style.visibility=\'visible\';
                  }else{
                     document.getElementById(id).style.visibility=\'hidden\';
                  }
                  if (document.getElementById(id).style.display==\'none\') {
                     document.getElementById(id).style.display=\'\';
                  }else{
                     document.getElementById(id).style.display=\'none\';
                  }
                  return false;
               }
               ';
        /*$jsCode .= '
          function selfHiddePopupInformation(){
             this.style.visibility = \'hidden\';
          }
          function selfShowPopupInformation(){
              this.style.visibility = \'visible\';
          }';*/
        CopixHtmlHeader::addJsCode($jsCode);
        $_init = true;
    }
    if (is_null($content)) {
        return;
    }
    if (!isset($params['text'])) {
        $params['text'] = '';
    }
    if (!isset($params['displaytext'])) {
        $params['displaytext'] = false;
    }
    if (!isset($params['alternativlink'])) {
        $params['alternativlink'] = '#';
    }
    if (!isset($params['displayimg'])) {
        $params['displayimg'] = true;
    }
    if (!isset($params['img'])) {
        $params['img'] = CopixUrl::get() . 'img/tools/information.png';
    }
    if (!isset($params['divclass'])) {
        $params['divclass'] = 'popupInformation';
    }
    if (!isset($params['handler'])) {
        $params['handler'] = 'onmouseover';
    }
    $id = uniqid('popupInformation');
    switch ($params['handler']) {
        case 'onmouseover':
            $toReturn = '<div id="div' . $id . '" style="display:inline;" ';
            $toReturn .= 'onmouseover="javascript:displayPopupInformation(\'' . $id . '\')" onmouseout="javascript:hidePopupInformation(\'' . $id . '\');" >';
            break;
        case 'onclick':
            $toReturn = '<a id="a' . $id . '" href="' . $params['alternativlink'] . '" ';
            $toReturn .= 'onclick="return toggleDisplayPopupInformation(\'' . $id . '\')">';
            break;
        case 'overEvent':
            $toReturn = '<div id="div' . $id . '" style="display:inline;" ';
            $toReturn .= 'onmouseover="javascript:displayPopupInformation(\'' . $id . '\')" onmouseout="javascript:hidePopupInformation(\'' . $id . '\')" onblur="javascript:hidePopupInformation(\'' . $id . '\')">';
            break;
        default:
            $toReturn = '<div id="div' . $id . '" style="display:inline;" ';
            $toReturn .= 'onmouseover="javascript:displayPopupInformation(\'' . $id . '\')" onmouseout="javascript:hidePopupInformation(\'' . $id . '\');" >';
            break;
    }
    $toReturn .= $params['displayimg'] === true ? '<img src="' . $params['img'] . '" alt="' . $params['text'] . '" />' : '';
    $toReturn .= $params['displaytext'] === true ? $params['text'] : '';
    if ($params['handler'] == 'onclick') {
        $toReturn .= '</a>';
    }
    $toReturn .= '<div class="' . $params['divclass'] . '" id="' . $id . '" style="visibility:hidden;';
    $toReturn .= $params['handler'] != 'onclick' ? '" >' : 'display:none" >';
    $toReturn .= $content;
    $toReturn .= '</div>';
    if ($params['handler'] != 'onclick') {
        $toReturn .= '</div>';
    }
    if (isset($params['assign'])) {
        $this->assign($params['assign'], $toReturn);
        return '';
    } else {
        return $toReturn;
    }
}
function smarty_function_htmleditor($params, &$smarty)
{
    static $_init = false;
    extract($params);
    //check the initialisation
    if (!$_init) {
        switch (strtolower(CopixConfig::get('htmleditor|type'))) {
            case 'htmlarea':
                CopixHtmlHeader::addJsCode('_editor_url = "' . CopixUrl::get() . 'js/htmlarea/";');
                //path of the library
                if (empty($htmlPath)) {
                    $htmlPath = CopixUrl::get() . 'js/htmlarea/';
                    //default path under CopiX
                }
                CopixHTMLHeader::addJSLink($htmlPath . 'htmlarea.js');
                CopixHTMLHeader::addJSLink($htmlPath . 'dialog.js');
                if (empty($lang)) {
                    $lang = CopixI18N::getLang();
                }
                CopixHTMLHeader::addJSLink($htmlPath . 'lang/' . $lang . '.js');
                CopixHTMLHeader::addCSSLink($htmlPath . 'htmlarea.css');
                CopixHTMLHeader::addJSLink($htmlPath . 'popupwin.js');
                $jsCode = 'HTMLArea.loadPlugin("TableOperations");
                HTMLArea.loadPlugin("InsertAnchor");
                HTMLArea.loadPlugin("TableToggleBorder");
                HTMLArea.loadPlugin("ContextMenu");';
                if (CopixModule::isValid('pictures') && CopixModule::isValid('cms') && CopixModule::isValid('document')) {
                    $jsCode = 'HTMLArea.loadPlugin("AstonTools");';
                }
                CopixHTMLHeader::addJSCode($jsCode);
                break;
            case 'fckeditor':
            default:
                $path = COPIX_MODULE_PATH . 'htmleditor/' . COPIX_CLASSES_DIR;
                $htmlPath = CopixUrl::get() . 'js/FCKeditor/';
                require_once $path . 'fckeditor.php';
                break;
        }
        //     CopixHTMLHeader::addJSLink ($path.'fckconfig.js');
        //		 CopixHTMLHeader::addJSLink ($path.'fckeditor.js');
        $_init = true;
    }
    if (empty($content)) {
        $content = '&nbsp;';
    }
    //name of the textarea.
    if (empty($name)) {
        $smarty->trigger_error('htmleditor: missing name parameter');
    } else {
        if (!$width) {
            $width = CopixConfig::get('htmleditor|width');
            //$width = '100%';
        }
        if (!$height) {
            $height = CopixConfig::get('htmleditor|height');
            //$height = '450px';
        }
        switch (strtolower(CopixConfig::get('htmleditor|type'))) {
            case 'htmlarea':
                $out = '<textarea id="' . $name . '" name="' . $name . '" style="width: ' . $width . 'px; height:' . $height . 'px;" >' . $content . '</textarea>';
                $out .= '<script type="text/javascript" defer="1">
         var editor' . $name . ' = null;
         editor' . $name . ' = new HTMLArea("' . $name . '");
         editor' . $name . '.registerPlugin("TableOperations");
         editor' . $name . '.registerPlugin("TableToggleBorder");
         editor' . $name . '.registerPlugin("InsertAnchor");
         editor' . $name . '.registerPlugin("ContextMenu");';
                if (CopixModule::isValid('pictures') && CopixModule::isValid('cms') && CopixModule::isValid('document')) {
                    $out .= 'editor' . $name . '.registerPlugin("AstonTools");';
                }
                $out .= 'editor' . $name . '.config.pageStyle = "@import url(\\"' . CopixUrl::get() . 'styles/styles_copix.css\\");";
         editor' . $name . '.generate ();
         </script>';
                break;
            case 'fckeditor':
            default:
                /*
                 * ATTENTION les éléments de config viewPhototèque etc font doublon avec la sélection de la toolbarset, mais sont nécessaire à Copix
                 * Par contre si on ne les load pas, on a une erreur de FCKeditor, il faut donc supprimer ce gestionnaire d'erreur sinon on se prend un alert javascript
                 * le gestionnaire en question se trouve dans "FCKToolbarItems.GetItem" (chercher cette chaîne pour le trouver) et désactiver "alert( FCKLang.UnknownToolbarItem.replace( /%1/g, itemName ) ) ;"
                 */
                $oFCKeditor = new FCKeditor($name);
                $oFCKeditor->BasePath = $htmlPath;
                $oFCKeditor->Value = $content;
                $oFCKeditor->ToolbarSet = 'Copix';
                $oFCKeditor->Width = $width;
                $oFCKeditor->Height = $height;
                $oFCKeditor->Config['viewPhototheque'] = CopixModule::isValid('pictures') ? 'true' : 'false';
                $oFCKeditor->Config['viewCmsLink'] = CopixModule::isValid('cms') ? 'true' : 'false';
                $oFCKeditor->Config['viewLinkPopup'] = CopixModule::isValid('cms') ? 'true' : 'false';
                $oFCKeditor->Config['viewDocument'] = CopixModule::isValid('document') ? 'true' : 'false';
                // Configuration de la feuille de style à utiliser.
                $oFCKeditor->Config['EditorAreaCSS'] = CopixUrl::get() . 'styles/styles_copix.css';
                $out = $oFCKeditor->CreateHtml();
                break;
        }
    }
    return $out;
}