home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 April / CMCD0404.ISO / Software / Freeware / Programare / groupoffice-com-2.01 / controls / wysiwyg.inc < prev   
Text File  |  2004-03-08  |  13KB  |  267 lines

  1. <?php
  2. /*////////////////////////////////////////////////////////////////////////////////
  3. //                                                                                //
  4. // Author: Merijn Schering <mschering@intermesh.nl>                                   //
  5. // Version: 1.0 Release date: 14 March 2003                                        //
  6. //                                                                                //
  7. ////////////////////////////////////////////////////////////////////////////////*/
  8.  
  9. if ($editor_html == '')
  10. {
  11.     $editor_html = '<html><head><meta http-equiv=Content-Type content="text/html; charset='.$charset.'"><meta content="'.$GO_CONFIG->title.' '.$GO_CONFIG->version.'" name="GENERATOR"><style>P {margin: 0px;}</style></head><body>'.$editor_html.'</body></html>';
  12. }else
  13. {
  14.     $editor_html = str_replace("\r", "",$editor_html);
  15.     $editor_html = str_replace("\n", "",$editor_html);
  16. }
  17. ?>
  18. <input type="hidden" name="editor_html" />
  19. <script language="JavaScript">
  20.  
  21.  
  22.   var viewMode = 1; // WYSIWYG
  23.  
  24.   function Init()
  25.   {
  26.     iView.document.write('<?php echo $editor_html; ?>');
  27.     iView.document.designMode = 'On';
  28.     iView.focus();
  29.   }
  30.  
  31.   function selOn(ctrl)
  32.   {
  33.     ctrl.style.borderColor = '#000000';
  34.     ctrl.style.backgroundColor = '#B5BED6';
  35.     ctrl.style.cursor = 'hand';
  36.   }
  37.  
  38.   function selOff(ctrl)
  39.   {
  40.     ctrl.style.borderColor = '';
  41.     ctrl.style.backgroundColor = '';
  42.   }
  43.  
  44.   function selDown(ctrl)
  45.   {
  46.     ctrl.style.backgroundColor = '#8492B5';
  47.   }
  48.  
  49.   function selUp(ctrl)
  50.   {
  51.     ctrl.style.backgroundColor = '#B5BED6';
  52.   }
  53.  
  54.   function callCommand(command)
  55.   {
  56.         iView.focus();
  57.         iView.document.execCommand(command, false, null);
  58.   }
  59.  
  60.   function doForeCol()
  61.   {
  62.       iView.focus();
  63.       var popup = window.open('<?php echo $GO_CONFIG->control_url; ?>color_picker.php?set=forecolor', '_blank', 'width=305,height=75,scrollbars=no,resizable=no,status=no');
  64.     if (!popup.opener) popup.opener = self;
  65.     popup.focus();
  66.   }
  67.  
  68.   function doBackCol()
  69.   {
  70.       iView.focus();
  71.       var popup = window.open('<?php echo $GO_CONFIG->control_url; ?>color_picker.php?set=backcolor', '_blank', 'width=305,height=75,scrollbars=no,resizable=no,status=no');
  72.     if (!popup.opener) popup.opener = self;
  73.     popup.focus();
  74.   }
  75.  
  76.   function doImage()
  77.   {
  78.         iView.focus();
  79.           <?php
  80.           if ($GO_MODULES->id = 'email')
  81.           {
  82.             if ($module = $GO_MODULES->get_module('filesystem'))
  83.             {
  84.                 if ($GO_SECURITY->has_permission($GO_SECURITY->user_id, $module['acl_read']) || $GO_SECURITY->has_permission($GO_SECURITY->user_id, $module['acl_write']))
  85.                 {
  86.                       echo 'popup(\'select_image.php\',\'600\',\'400\')';
  87.                 }
  88.             }
  89.         }
  90.           ?>
  91.   }
  92.  
  93.   function doFont(fName)
  94.   {
  95.       iView.focus();
  96.     if(fName != '')
  97.       iView.document.execCommand('fontname', false, fName);
  98.   }
  99.  
  100.   function doSize(fSize)
  101.   {
  102.       iView.focus();
  103.     if(fSize != '')
  104.       iView.document.execCommand('fontsize', false, fSize);
  105.   }
  106.  
  107.   function doHead(hType)
  108.   {
  109.       iView.focus();
  110.     if(hType != '')
  111.     {
  112.       iView.document.execCommand('formatblock', false, hType);
  113.       doFont(document.forms[0].selFont.options[document.forms[0].selFont.selectedIndex].value);
  114.     }
  115.   }
  116.  
  117.   function doToggleView()
  118.   {
  119.     if(viewMode == 1)
  120.     {
  121.       iHTML = iView.document.body.innerHTML;
  122.       iView.document.body.innerText = iHTML;
  123.  
  124.       // Hide all controls
  125.       trControls.style.display = 'none';
  126.       tdControls.style.display = 'none';
  127.       document.forms[0].selFont.style.display = 'none';
  128.       document.forms[0].selSize.style.display = 'none';
  129.       document.forms[0].selHeading.style.display = 'none';
  130.       iView.focus();
  131.  
  132.       viewMode = 2; // Code
  133.     }
  134.     else
  135.     {
  136.       iText = iView.document.body.innerText;
  137.       iView.document.body.innerHTML = iText;
  138.  
  139.       // Show all controls
  140.       trControls.style.display = 'inline';
  141.       tdControls.style.display = 'inline';
  142.       document.forms[0].selFont.style.display = 'inline';
  143.       document.forms[0].selSize.style.display = 'inline';
  144.       document.forms[0].selHeading.style.display = 'inline';
  145.  
  146.       iView.focus();
  147.  
  148.       viewMode = 1; // WYSIWYG
  149.     }
  150.   }
  151.     function update_editor_html()
  152.     {
  153.         //document.forms[0].editor_html.value = iView.document.getElementsByTagName("html")[0].outerHTML;
  154.     }
  155.  
  156.  
  157. </script>
  158. <style>
  159.  
  160.   .butClass
  161.   {
  162.     border: 1px solid;
  163.     border-color: #D6D3CE;
  164.   }
  165.  
  166.   .tdClass
  167.   {
  168.     padding-left: 3px;
  169.     padding-top:3px;
  170.   }
  171.  
  172. </style>
  173.     <?php
  174.         if (!isset($editor_height)) $editor_height = '205';
  175.         if (!isset($editor_width)) $editor_width = '415';
  176.     ?>
  177.  
  178.     <table width="<?php echo $editor_width; ?>" height="<?php echo $editor_height; ?>" border="0" cellspacing="0" cellpadding="0">
  179.         <tr>
  180.             <td class="tdClass" colspan="1" valign="top" id="tdControls" height="30px" nowrap>
  181.             <?php
  182.                 $selFont = isset($selFont) ? $selFont : '';
  183.                 $dropbox = new dropbox();
  184.                 $dropbox->add_value("","-- ".$editor_font." --");
  185.                 $dropbox->add_value("Arial","Arial");
  186.                 $dropbox->add_value("Times New Roman","Times New Roman");
  187.                 $dropbox->add_value("Verdana","Verdana");
  188.                 $dropbox->add_value("Courier","Courier");
  189.                 $dropbox->add_value("MS Sans Serif","MS Sans Serif");
  190.                 $dropbox->add_value("Comic Sans MS","Comic Sans MS");
  191.                 $dropbox->add_value("Tahoma","Tahoma");
  192.                 $dropbox->add_value("Wingdings","Wingdings");
  193.                 $dropbox->print_dropbox("selFont", $selFont, 'onchange="doFont(this.options[this.selectedIndex].value)"');
  194.  
  195.                 $selSize = isset($selSize) ? $selSize : '';
  196.                   $dropbox = new dropbox();
  197.                 $dropbox->add_value("","-- ".$editor_size." --");
  198.                 $dropbox->add_value("1",$editor_very_small);
  199.                 $dropbox->add_value("2",$editor_small);
  200.                 $dropbox->add_value("3",$editor_medium);
  201.                 $dropbox->add_value("4",$editor_large);
  202.                 $dropbox->add_value("5",$editor_larger);
  203.                 $dropbox->add_value("6",$editor_very_large);
  204.                 $dropbox->print_dropbox("selSize",$selSize,'onchange="doSize(this.options[this.selectedIndex].value)"');
  205.  
  206.                 $selHeading = isset($selHeading) ? $selHeading : '';
  207.                   $dropbox = new dropbox();
  208.                 $dropbox->add_value("","-- ".$editor_heading." --");
  209.                 $dropbox->add_value("Heading 1","H1");
  210.                 $dropbox->add_value("Heading 2","H2");
  211.                 $dropbox->add_value("Heading 3","H3");
  212.                 $dropbox->add_value("Heading 4","H4");
  213.                 $dropbox->add_value("Heading 5","H5");
  214.                 $dropbox->add_value("Heading 6","H6");
  215.                 $dropbox->print_dropbox("selHeading", $selHeading,'onchange="doHead(this.options[this.selectedIndex].value)"');
  216.             ?>
  217.                   <img alt="<?php echo $editor_bold; ?>" class="butClass" src="<?php echo $GO_THEME->images['bold']; ?>" onMouseOver="selOn(this)" onMouseOut="selOff(this)" onMouseDown="selDown(this)" onMouseUp="selUp(this)" onClick="callCommand('bold')">
  218.                   <img alt="<?php echo $editor_italic; ?>" class="butClass" src="<?php echo $GO_THEME->images['italic']; ?>" onMouseOver="selOn(this)" onMouseOut="selOff(this)" onMouseDown="selDown(this)" onMouseUp="selUp(this)" onClick="callCommand('italic')">
  219.                   <img alt="<?php echo $editor_underline; ?>" class="butClass" src="<?php echo $GO_THEME->images['underline']; ?>" onMouseOver="selOn(this)" onMouseOut="selOff(this)" onMouseDown="selDown(this)" onMouseUp="selUp(this)" onClick="callCommand('underline')">
  220.                 <img alt="<?php echo $editor_strikethrough; ?>" class="butClass" src="<?php echo $GO_THEME->images['strikethrough']; ?>" onMouseOver="selOn(this)" onMouseOut="selOff(this)" onMouseDown="selDown(this)" onMouseUp="selUp(this)" onClick="callCommand('StrikeThrough')">
  221.                  
  222.                 <img alt="<?php echo $editor_superscript; ?>" class="butClass" src="<?php echo $GO_THEME->images['superscript']; ?>" onMouseOver="selOn(this)" onMouseOut="selOff(this)" onMouseDown="selDown(this)" onMouseUp="selUp(this)" onClick="callCommand('superscript')">
  223.                 <img alt="<?php echo $editor_subscript; ?>" class="butClass" src="<?php echo $GO_THEME->images['subscript']; ?>" onMouseOver="selOn(this)" onMouseOut="selOff(this)" onMouseDown="selDown(this)" onMouseUp="selUp(this)" onClick="callCommand('subscript')">
  224.  
  225.             </td>
  226.             <td class="tdClass" align="right">
  227.               <img alt="<?php echo $editor_mode; ?>" class="butClass" src="<?php echo $GO_THEME->images['mode']; ?>" onMouseOver="selOn(this)" onMouseOut="selOff(this)" onMouseDown="selDown(this)" onMouseUp="selUp(this)" onClick="doToggleView()">
  228.             </td>
  229.         </tr>
  230.            <tr id="trControls">
  231.                 <td class="tdClass" colspan="3" nowrap>
  232.  
  233.                     <img alt="<?php echo $editor_left; ?>" class="butClass" src="<?php echo $GO_THEME->images['left']; ?>" onMouseOver="selOn(this)" onMouseOut="selOff(this)" onMouseDown="selDown(this)" onMouseUp="selUp(this)" onClick="callCommand('justifyleft')">
  234.                     <img alt="<?php echo $editor_center; ?>" class="butClass" src="<?php echo $GO_THEME->images['center']; ?>" onMouseOver="selOn(this)" onMouseOut="selOff(this)" onMouseDown="selDown(this)" onMouseUp="selUp(this)" onClick="callCommand('justifycenter')">
  235.                     <img alt="<?php echo $editor_right; ?>" class="butClass" src="<?php echo $GO_THEME->images['right']; ?>" onMouseOver="selOn(this)" onMouseOut="selOff(this)" onMouseDown="selDown(this)" onMouseUp="selUp(this)" onClick="callCommand('justifyright')">
  236.                     <img alt="<?php echo $editor_outdent; ?>" class="butClass" src="<?php echo $GO_THEME->images['outdent']; ?>" onMouseOver="selOn(this)" onMouseOut="selOff(this)" onMouseDown="selDown(this)" onMouseUp="selUp(this)" onClick="callCommand('outdent')">
  237.                     <img alt="<?php echo $editor_indent; ?>" class="butClass" src="<?php echo $GO_THEME->images['indent']; ?>" onMouseOver="selOn(this)" onMouseOut="selOff(this)" onMouseDown="selDown(this)" onMouseUp="selUp(this)" onClick="callCommand('indent')">
  238.                      
  239.                     <img alt="<?php echo $editor_ord_list; ?>" class="butClass" src="<?php echo $GO_THEME->images['ordlist']; ?>" onMouseOver="selOn(this)" onMouseOut="selOff(this)" onMouseDown="selDown(this)" onMouseUp="selUp(this)" onClick="callCommand('insertorderedlist')">
  240.                     <img alt="<?php echo $editor_bul_list; ?>" class="butClass" src="<?php echo $GO_THEME->images['bullist']; ?>" onMouseOver="selOn(this)" onMouseOut="selOff(this)" onMouseDown="selDown(this)" onMouseUp="selUp(this)" onClick="callCommand('insertunorderedlist')">
  241.                      
  242.                     <img alt="<?php echo $editor_undo; ?>" class="butClass" src="<?php echo $GO_THEME->images['undo']; ?>" onMouseOver="selOn(this)" onMouseOut="selOff(this)" onMouseDown="selDown(this)" onMouseUp="selUp(this)" onClick="callCommand('undo')">
  243.                     <img alt="<?php echo $editor_redo; ?>" class="butClass" src="<?php echo $GO_THEME->images['redo']; ?>" onMouseOver="selOn(this)" onMouseOut="selOff(this)" onMouseDown="selDown(this)" onMouseUp="selUp(this)" onClick="callCommand('redo')">
  244.                      
  245.                     <img alt="<?php echo $editor_txt_color; ?>" class="butClass" src="<?php echo $GO_THEME->images['textcolor']; ?>" onMouseOver="selOn(this)" onMouseOut="selOff(this)" onMouseDown="selDown(this)" onMouseUp="selUp(this)" onClick="doForeCol()">
  246.                     <img alt="<?php echo $editor_back_color; ?>" class="butClass" src="<?php echo $GO_THEME->images['bg_color']; ?>" onMouseOver="selOn(this)" onMouseOut="selOff(this)" onMouseDown="selDown(this)" onMouseUp="selUp(this)" onClick="doBackCol()">
  247.                      
  248.                     <img alt="<?php echo $editor_hyperlink; ?>" class="butClass" src="<?php echo $GO_THEME->images['link']; ?>" onMouseOver="selOn(this)" onMouseOut="selOff(this)" onMouseDown="selDown(this)" onMouseUp="selUp(this)" onClick="callCommand('createlink')">
  249.                     <img alt="<?php echo $editor_image; ?>" class="butClass" src="<?php echo $GO_THEME->images['image']; ?>" onMouseOver="selOn(this)" onMouseOut="selOff(this)" onMouseDown="selDown(this)" onMouseUp="selUp(this)" onClick="doImage()">
  250.                     <img alt="<?php echo $editor_rule; ?>" class="butClass" src="<?php echo $GO_THEME->images['rule']; ?>" onMouseOver="selOn(this)" onMouseOut="selOff(this)" onMouseDown="selDown(this)" onMouseUp="selUp(this)" onClick="callCommand('inserthorizontalrule')">
  251.                      
  252.                     <img alt="<?php echo $editor_copy; ?>" class="butClass" src="<?php echo $GO_THEME->images['copy_small']; ?>" onMouseOver="selOn(this)" onMouseOut="selOff(this)" onMouseDown="selDown(this)" onMouseUp="selUp(this)" onClick="callCommand('copy')">
  253.                     <img alt="<?php echo $editor_cut; ?>" class="butClass" src="<?php echo $GO_THEME->images['cut_small']; ?>" onMouseOver="selOn(this)" onMouseOut="selOff(this)" onMouseDown="selDown(this)" onMouseUp="selUp(this)" onClick="callCommand('cut')">
  254.                     <img alt="<?php echo $editor_paste; ?>" class="butClass" src="<?php echo $GO_THEME->images['paste_small']; ?>" onMouseOver="selOn(this)" onMouseOut="selOff(this)" onMouseDown="selDown(this)" onMouseUp="selUp(this)" onClick="callCommand('paste')">
  255.  
  256.                 </td>
  257.             </tr>
  258.         <tr>
  259.         <td width="100%" height="100%" colspan="3">
  260.         <iframe id="iView" name="editor" style="width: 100%; height: 100%;" onBlur="javascript:update_editor_html()"></iframe>
  261.         </td>
  262.     </tr>
  263.     </table>
  264.  
  265.  
  266.  
  267.