1   <?php
  2   ##############################################################
  3   ##   In-portal :: Administration Interfaces :: Tool Bar     ##
  4   ##############################################################
  5   ##                   In-portal                     ##
  6   ##             Intechnic Corporation               ##
  7   ##          All Rights Reserved, 1998-2002            ##
  8   ##                                           ##
  9   ## No portion of this code may be copied, reproduced or  ##
  10   ##    otherwise redistributed without proper written     ##
  11   ##   consent of Intechnic Corporation.  Violation will      ##
  12   ##    result in revocation of the license and support    ##
  13   ##  privileges along maximum prosecution allowed by law. ##
  14   ##############################################################
  15  
  16   class clsToolBarItem
  17   {
  18      var $m_img;
  19      var $m_alt;
  20      var $link
  21      var $onMouseOver;
  22      var $onMouseOut;
  23      var $onClick;
  24      var $filename;
  25  
  26      function clsToolBarItem()
  27      {
  28      }
  29  
  30      function GetItem()
  31      {
  32          global $imagesURL;
  33          $o = "";
  34          if ($this->img=="divider")
  35          {
  36              $o .= "<img src=\"".$imagesURL."/toolbar/tool_divider.gif\" width=\"4\" height=\"32\" border=\"0\">\n";
  37          }
  38          else
  39          {
  40              if(strlen($this->link)>1)
  41              {          
  42                $o .= "<a href=\"".$this->link."\" onMouseOut=\"".$this->onMouseOut."\"";
  43                $o .= " onMouseOver=\"".$this->onMouseOver."\" onClick=\"".$this->onClick."\">\n";
  44                $o .= "<img ID=\"".$this->img."\" title=\"".inp_htmlize(language($this->alt))."\" src=\"".$this->filename."\" width=\"32\" height=\"32\" border=\"0\">";
  45                $o .= "</a>\n";
  46              }
  47              else
  48              {
  49                $o .= "<img ID=\"".$this->img."\" title=\"".inp_htmlize(language($this->alt))."\" src=\"".$this->filename."\" width=\"32\" height=\"32\" border=\"0\"";
  50                $o .= " onMouseOut=\"".$this->onMouseOut."\"";
  51                $o .= " onMouseOver=\"".$this->onMouseOver."\" onClick=\"".$this->onClick."\">";
  52              }
  53          }
  54          return $o;
  55      }
  56     
  57      function GetID()
  58      {
  59                   // get image id (for javascript operations)
  60                   return $this->img;
  61      }
  62   }
  63  
  64   class clsToolBar
  65   {
  66       var $Items;
  67       var $m_section;
  68       var $m_load_menu_func;
  69       var $m_CheckClass;
  70       var $m_CheckForm;
  71       var $InitScript;
  72           var $DoubleClickAction;
  73           var $ContextMenu;
  74           
  75       function clsToolBar()
  76       {
  77           $this->Items =  array();
  78           $this->InitScript = array();
  79           $this->ContextMenu = array();
  80       }
  81  
  82       function Get($name)
  83      { 
  84           $var = "m_" . $name;
  85         return $this->$var;
  86      }
  87  
  88      function Set($name, $value)
  89      { 
  90         if (is_array($name))
  91         {
  92            for ($i=0; $i<sizeof($name); $i++)
  93            {  $var = "m_" . $name[$i];
  94               $this->$var = $value[$i];
  95               $this->m_dirtyFieldsMap[$name[$i]] = $value[$i];
  96                   echo "$var = ".$value[$i]."<br>\n";
  97            }
  98         }
  99         else
  100         {
  101         $var = "m_" . $name;
  102         $this->$var = $value;
  103         $this->m_dirtyFieldsMap[$name] = $value;
  104         }
  105      }
  106  
  107       function Add($img,$alt="",$link="",$MouseOver="",$MouseOut="",$onClick="", $filename="",$IsDblClick=FALSE,$ContextMenu=FALSE)
  108       {
  109         global $imagesURL;
  110         $t = new clsToolBarItem();
  111         $t->img = $img;
  112         $t->alt = $alt;
  113         $t->link = $link;
  114         $t->onMouseOver = $MouseOver;
  115         $t->onMouseOut = $MouseOut;
  116         $t->onClick = $onClick;
  117         if(strlen($filename)==0)
  118         {
  119             $t->filename = $imagesURL."/toolbar/tool_".$img.".gif";
  120         }
  121         else
  122         {
  123             if(substr($filename,0,4)=="http")
  124             {         
  125               $t->filename = $filename;
  126             }
  127             else
  128             {
  129                   if(substr($filename,0,8)!="toolbar/")
  130                     $filename = "toolbar/".$filename;                             
  131                   if(substr($filename,0,1)!="/")
  132                     $filename = "/".$filename;                    
  133               $t->filename = $imagesURL.$filename;
  134             }
  135         }
  136         array_push($this->Items,$t);
  137         if($IsDblClick)
  138           $this->DoubleClickAction=$onClick;
  139         if($ContextMenu)
  140           $this->ContextMenu[] = "contextMenu.addMenuItem('".admin_language($alt)."',\"$onClick\",\"\");";
  141         return $t;
  142       }
  143  
  144       function AddToInitScript($s)
  145       {
  146         if(is_array($s))
  147         {
  148             for($i=0;$i<count($s);$i++)
  149                 array_push($this->InitScript,$s[$i]);
  150         }
  151         else
  152             array_push($this->InitScript,$s);
  153       }
  154  
  155       function GetInitScript()
  156       {
  157           global $envar;
  158           $s="";
  159  
  160           if(count($this->InitScript)>0)
  161             $s = implode("\n",$this->InitScript);
  162           if(strlen($this->Get("CheckClass")))
  163           {               
  164                   $c = $this->Get("CheckClass")." = new CheckArray();\n";
  165                   $c .=$this->Get("CheckClass").".formname='".$this->Get("CheckForm")."';\n";
  166                   $c .=$this->Get("CheckClass").".envar='$envar';\n";
  167                   $s = $c.$s;
  168           }
  169           $s .= "\n".$this->GetActionHandlerScript();
  170   //        $s .= "\n".$this->Get("CheckClass").".setImages();\n";
  171           return "<SCRIPT language=\"JavaScript\">$s</SCRIPT>";
  172       }
  173      
  174       function GetActionHandlerScript()
  175       {   
  176           $o = '';
  177  
  178                   $o .= "function handleDoubleClick()\n{\n";
  179           
  180                   if(strlen($this->DoubleClickAction)>0)
  181           {
  182                           $o .= "  ".$this->DoubleClickAction."\n";
  183           }
  184           else {
  185                   $o .= 'return';
  186           }
  187                   
  188           $o .= "}\n\n";
  189           
  190                   if(count($this->ContextMenu))
  191                   {
  192                           $o .= "function initContextMenu()\n{\n";
  193                           $o .= "  window.contextMenu = new Menu(\"Context\");";
  194                           for($x=0;$x<count($this->ContextMenu);$x++)
  195                           {
  196                                   $o .= "  ".$this->ContextMenu[$x]."\n";
  197                           }
  198                           $o .= "  window.triedToWriteMenus = false;\n  window.contextMenu.writeMenus();\n  return true;\n}\n";
  199                   }
  200           return $o;
  201       }
  202      
  203       function Build()
  204       {                  
  205           global $imagesURL;
  206           $btn_ids = Array();
  207          
  208           $o'<table border="0" cellpadding="0" cellspacing="0" width="100%" class="toolbar">';
  209           //$o .= '<tr><td><img title="|" src="'.$imagesURL.'/toolbar_start.gif" width="10" height="50" border="0"></td>'."\n";
  210           foreach($this->Items as $t)
  211           {
  212             $o .= '<TD>'.$t->GetItem().'</TD>';
  213             $btn_ids[] = $t->GetID();
  214           }
  215           $o .= '<TD width="100%"></TD></TR></TABLE>'."\n";
  216          
  217           $btn_ids = "'".implode("','", $btn_ids)."'";
  218           $o .= '<script language="javascript">
  219                           var toolbar_btns = Array('.$btn_ids.');
  220                           var i = 0, btn_count = toolbar_btns.length;
  221                           while(i < btn_count)
  222                           {
  223                                   SetButtonStateByImage(toolbar_btns[i]);
  224                                   i++;    
  225                           }
  226                           </script>';
  227          
  228           return $o;
  229       }
  230  
  231       function onLoadString()
  232       {
  233           return "";
  234       }
  235   }
  236  
  237   class clsItemTabs
  238   {
  239     var $Tabs;
  240     var $ItemCount;
  241  
  242     function clsItemTabs()
  243     {
  244         $this->Tabs = array();
  245         $this->ItemCount = array();
  246     }
  247  
  248     function SetItemCount($divname,$Value)
  249     {
  250         $this->ItemCount[$divname] = $Value;
  251     }
  252  
  253     function GetItemCount($divname)
  254     {
  255         return (int)$this->ItemCount[$divname];
  256     }
  257  
  258     function AddTab($Caption,$divname,$ItemCount,$selected,$numfunc="")
  259     {
  260         $t["caption"]=$Caption;
  261         $t["divname"]=$divname;
  262         $this->SetItemCount($divname,$ItemCount);
  263         $t["selected"]=$selected;
  264         $t["numfunc"]=$numfunc;
  265         $this->Tabs[] = $t;
  266     }
  267    
  268     function TabItem($i)
  269     {
  270         global $imagesURL;
  271  
  272         $t = $this->Tabs[$i];
  273         if($t["selected"]==1)
  274         {
  275           $divimage="/divider_up.gif";
  276         }
  277         else
  278           $divimage="/divider_dn.gif";
  279  
  280         $div = $t["divname"];
  281         $o .= "<td width=\"138\" height=\"22\" noWrap";
  282         $o .= " background=\"".$imagesURL."/itemtabs/tab_inactive.gif\" ";
  283         $o .= "tabHeaderOf=\"$div\" ";
  284         $o .= "onclick=\"toggleTab('$div');\"  style=\"cursor:hand\">\n";
  285         $o .= "  <img height=\"20\"  src=\"".$imagesURL."/itemtabs/divider_empty.gif\" ";
  286         $o .= "width=\"20\" border=\"0\" align=\"middle\">";
  287         $o .= $t["caption"]."<span class=\"cats_stats\">";
  288         $func = $t["numfunc"];
  289         if(is_numeric($func))
  290         {
  291           $total = $func;
  292         }
  293         else
  294         {
  295           if(function_exists($func))
  296           {       
  297              $total = $func();
  298           }
  299         }
  300         if(!is_numeric($total))
  301           $total = $this->GetItemCount($div);
  302          
  303         if($total==$this->GetItemCount($div))
  304         {
  305           $o .= "(".$this->GetItemCount($div).")</span></td>\n";
  306         }
  307         else
  308           $o .= "(".$this->GetItemCount($div)." / ".$total.")</span></td>\n";
  309       
  310         return $o;
  311     }
  312  
  313     function tabRow()
  314     {
  315         $o = "<table width=\"100%\" border=0 cellspacing=0 cellpadding=0>";
  316         $o .= "<tr>";
  317         for($i=0;$i<count($this->Tabs);$i++)
  318         {
  319             $o .= $this->TabItem($i);
  320         }
  321         $o .= "<td width=\"100%\"></td>";
  322         //$o .= "<tr class=\"divider\">";
  323         //$o .= "<td colspan=4><img src=\"".$imagesURL."/spacer.gif\" border=0 width=1 height=1></td>";
  324         $o .= "</tr></table>";
  325         return $o;
  326     }
  327   }
  328  
  329   ?>