<?php
/**
 * VoiceOne Smarty Plugin
 *
 * Smarty function Menu
 * @package voiceone
 * @subpackage  smarty_menu
 */

function smarty_function_menu($params, &$smarty)
{
  global $cwUserInfo,$cwlang,$relBasePath, $cwlanguage;

  $section=$params["section"];
  $subsection=$params["subsection"];
  //Esempio: \Sites\callware3
  //$cwBasePath=substr(__FILE__,strlen(getenv("DOCUMENT_ROOT")),-strlen("\admin\public\plugin\function.menu.php"));
  //$cwBasePath=str_replace("\\","/",$cwBasePath);
	$cwBasePath=$relBasePath."..";


  /************************************************/
  /**************  SETTINGS MENU'  ****************/
  /************************************************/
  if (strpos(getenv("REQUEST_URI"),"settings")>0) {
    /**
     * Se un utente USER entra in una pagina che contiene nell'url la parola "settings"
     * viene rediretto della pagina precedente (../)
     **/
    if($cwUserInfo["type"]==USER_STANDARD){
      echo "<script>location.href='../';</script>"; die();
    }
    /**
     * Se un utente CONFIGURATOR entra in una pagina che contiene nell'url la parola "settings"
     * e un termine presente nella blacklist viene rediretto della pagina precedente (../)
     **/
    if($cwUserInfo["type"]==USER_CONFIGURATOR){
      $blackList=array("trunk/","plugin/","tech/","macro/","cli/","editor/","backup/","network/");
      foreach($blackList as $blackpage){
        if(strpos(getenv("REQUEST_URI"),$blackpage)>0){
          echo "<script>location.href='../';</script>"; die();
        }
      }
    }
    /**
     * Calcolo la pagina selezionata impostandone la classe "current"
     **/
    if ($section=="settings")   $overview=" class=\"current\" "; else $overview="";
    if ($section=="extensions") $extensions=" class=\"current\" "; else $extensions="";
    if ($section=="groups")     $groups=" class=\"current\" "; else $groups="";
    if ($section=="rules")      $rules=" class=\"current\" "; else $rules="";
    if ($section=="sounds")     $sounds=" class=\"current\" "; else $sounds="";
    if ($section=="moh")        $moh=" class=\"current\" "; else $moh="";
    if ($section=="ivr")        $ivr=" class=\"current\" "; else $ivr="";
    if ($section=="application") $application=" class=\"current\" "; else $application="";
    if ($section=="queue"   or
        $section=="agents"   or
        $section=="queueoptions" ) $queue=" class=\"current\" "; else $queue="";
    if ($section=="meetme")     $meetme=" class=\"current\" "; else $meetme="";
    //if ($section=="plugin")     $plugin=" class=\"current\" "; else $plugin="";
    if ($section=="alltrunks" or
        $section=="providers" or
        $section=="offices"   or
        $section=="misdnGroup" or
        $section=="zapGroup")    $trunk=" class=\"current\" "; else $trunk="";
    if ($section=="tech"    or
        $section=="isdn"    or
        $section=="sip"     or
        $section=="zapata"  or
        $section=="iax" )       $tech=" class=\"current\" "; else $tech="";
    if ($section=="user")       $user=" class=\"current\" "; else $user="";
    if ($section=="system")     $system=" class=\"current\" "; else $system="";
    // Print menu
    ?>
    <ul id="Tabs">
      <!-- align left -->
		  <li><a href="<?=$cwBasePath?>/settings"                  title="" <?=$overview?>   ><?=T_("Overview")?></a></li>
  	  <li><a href="<?=$cwBasePath?>/settings/extensions"       title="" <?=$extensions?> ><?=T_("Extensions")?></a></li>
      <li><a href="<?=$cwBasePath?>/settings/groups"           title="" <?=$groups?>     ><?=T_("Groups")?></a></li>
  	  <li><a href="<?=$cwBasePath?>/settings/queue"            title="" <?=$queue?>      ><?=T_("Queues")?></a></li>
      <li><a href="<?=$cwBasePath?>/settings/meetme"           title="" <?=$meetme?>     ><?=T_("Conference")?></a></li>
      <li><a href="<?=$cwBasePath?>/settings/ivr"              title="" <?=$ivr?>        ><?=T_("IVR")?>          </a></li>
      <li><a href="<?=$cwBasePath?>/settings/sounds"           title="" <?=$sounds?>     ><?=T_("Sounds")?>       </a></li>
      <li><a href="<?=$cwBasePath?>/settings/moh"              title="" <?=$moh?>        ><?=T_("MOH")?>          </a></li>
      <li><a href="<?=$cwBasePath?>/settings/rules/outgoing"   title="" <?=$rules?>      ><?=T_("Rules")?>        </a></li>
      <li><a href="<?=$cwBasePath?>/settings/tool/application/" title="" <?=$application?>><?=T_("Applications")?></a></li>
      <!-- align right -->
      <li><a href="<?=$cwBasePath?>/settings/system/io"        title="" <?=$system?> style="float: right; margin-right: 20px;"> <?=T_("System")?></a></li>
      <li><a href="<?=$cwBasePath?>/settings/user"             title="" <?=$user?>   style="float: right;">                     <?=T_("Users")?>  </a></li>
    <? if ($cwUserInfo["type"]==USER_SUPERUSER) { ?>
       <!-- align right -->
      <li><a href="<?=$cwBasePath?>/settings/trunk"            title="" <?=$trunk?>  style="float: right;">                     <?=T_("Lines")?> </a></li>
      <li><a href="<?=$cwBasePath?>/settings/tech"             title="" <?=$tech?>   style="float: right;"> <?=T_("Technologies")?>    </a></li>
      <!--li><a href="<?=$cwBasePath?>/settings/plugin"           title="" <?=$plugin?> style="float: right;"> <?=$cwlang["menu"]["plugin"]?>  </a></li-->
    <? } ?>
		</ul>
  <?
  }
  /************************************************/
  /**************  PERSONAL MENU  *****************/
  /************************************************/
  else {
    if ($section=="contacts") $contacts=" class=\"current\" "; else $contacts="";
    if ($section=="fax") $fax=" class=\"current\" "; else $fax="";
    if ($section=="callcenter") $callcenter=" class=\"current\" "; else $callcenter="";
    if ($section=="recording") $recording=" class=\"current\" "; else $recording="";
    //if ($section=="phone") $phone=" class=\"current\" "; else $phone="";
    //if ($section=="calls") $calls=" class=\"current\" "; else $calls="";
    //if ($section=="sms") $sms=" class=\"current\" "; else $sms="";
    if ($section=="voicemail") $voicemail=" class=\"current\" "; else $voicemail="";
    if ($section=="account") $account=" class=\"current\" "; else $account="";
    ob_start();
    ?>
    <ul id="Tabs">
  	  <li><a href="<?=$cwBasePath?>/"       title="" <?=$contacts?>  ><?=T_("PhoneBook")?>  </a></li>
      <? if((_isModuleLoaded('fax'))&&(_hasFaxAccess())){ ?>
        <li><a href="<?=$cwBasePath?>/fax"       title="" <?=$fax?>  ><?=T_("Fax")?>  </a></li>
      <? } ?>
      <? if((_isModuleLoaded('callcenter'))&&($cwUserInfo["type"]==USER_CONFIGURATOR OR $cwUserInfo["type"]==USER_SUPERUSER)){ ?>
        <li><a href="<?=$cwBasePath?>/callcenter"       title="" <?=$callcenter?>  ><?=T_("Callcenter")?>  </a></li>
      <? } ?>
      <? if((_isModuleLoaded('recording'))&&($cwUserInfo["type"]==USER_CONFIGURATOR OR $cwUserInfo["type"]==USER_SUPERUSER)){ ?>
        <li><a href="<?=$cwBasePath?>/recording"       title="" <?=$recording?>  ><?=T_("Recording")?>  </a></li>
      <? } ?>
  		<!--<li><a href="<?=$cwBasePath?>/phone/" title="" <?=$phone?>     ><?=$cwlang["menu"]["phone"]?>      </a></li>-->
    	<!--<li><a href="<?=$cwBasePath?>/calls"  title="" <?=$calls?>     ><?=$cwlang["menu"]["history"]?>    </a></li>-->
      <!--<li><a href="<?=$cwBasePath?>/sms" title="" <?=$sms?>  ><?=$cwlang["menu"]["sms"]?></a></li>-->
    <? if ($cwUserInfo["entity_id"]!=0) {?>
      <li><a href="<?=$cwBasePath?>/voicemail" title="" <?=$voicemail?>  ><?=T_("VoiceMail")?></a></li>
    <? } ?>
    <? if ($cwUserInfo["type"]==USER_CONFIGURATOR OR $cwUserInfo["type"]==USER_SUPERUSER) {?>
      <li><a href="<?=$cwBasePath?>/settings" title="" <?=$settings?> style="float: right; margin-right: 20px; color:red"> <?=T_("Configuration")?></a></li>
    <? }
       else $margin="margin-right: 20px;";
       if ($cwUserInfo["entity_id"]!=0) {?>
      <li><a href="<?=$cwBasePath?>/account" title="" <?=$account?> style="float: right; <?=$margin?>"> <?=T_("Account")?></a></li>
    <? } ?>
    </ul>
  <?
    $ret=ob_get_contents();
    ob_end_clean();
  }
  return $ret;
}
?>
