Changeset 9232

Show
Ignore:
Timestamp:
03/16/10 05:14:54 (2 years ago)
Author:
mbrevda
Message:

closes #1798; draw destinations as multiple select boxes. Finaly! Thanks to www.schmoozecom.com for their ongoing sponsorship and support

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • freepbx/trunk/amp_conf/htdocs/admin/functions.inc.php

    r9214 r9232  
    19841984 */    
    19851985function drawselects($goto,$i,$show_custom=false, $table=true) { 
    1986   global $tabindex; 
    1987    
    1988   /* --- MODULES BEGIN --- */ 
    1989   global $active_modules; 
    1990  
    1991   // this is global so we only populate it once and it is preserved afterwards 
    1992   global $drawselect_destinations; 
    1993   global $drawselects_module_hash; 
    1994  
    1995   $selectHtml=''; 
    1996   if($table){ 
    1997     $selectHtml.='<tr><td colspan=2>'; 
    1998   } 
    1999  
    2000   // check for module-specific destination functions 
    2001   // if isset() then we called this once, so don't call again just use the data 
    2002   // this can result in significant savings in IVRs and other pages that present 
    2003   // multiple destinations 
    2004   // 
    2005   if (!isset($drawselect_destinations)) { 
    2006     foreach ($active_modules as $rawmod => $module) { 
    2007       $funct = strtolower($rawmod.'_destinations'); 
    2008    
    2009       //if the modulename_destinations() function exits, run it and display selections for it 
    2010       if (function_exists($funct)) { 
    2011         $destArray = $funct(); //returns an array with 'destination' and 'description', and optionally 'category' 
    2012         if (is_Array($destArray)) { 
    2013           foreach ($destArray as $dest) { 
    2014             $cat = (isset($dest['category']) ? $dest['category'] : $module['displayname']); 
    2015             $drawselect_destinations[$cat][] = $dest; 
    2016             $drawselects_module_hash[$cat] = $rawmod; 
    2017           } 
    2018         } 
    2019       } 
    2020     } 
    2021     if (!isset($drawselect_destinations)) { 
    2022       $drawselect_destinations = array(); 
    2023     } 
    2024     if (!isset($drawselects_module_hash)) { 
    2025       $drawselects_module_hash = array(); 
    2026     } 
    2027   } 
    2028  
    2029   $foundone = false; 
    2030   $tabindex_needed = true; 
    2031   foreach ($drawselect_destinations as $cat=>$destination) { 
    2032     // create a select option for each destination  
    2033     $options = ""; 
    2034     $checked = false; 
    2035     foreach ($destination as $dest) { 
    2036       $options .= '<option value="'.$dest['destination'].'" '.(strpos($goto,$dest['destination']) === false ? '' : 'SELECTED').'>'.($dest['description'] ? $dest['description'] : $dest['destination']); 
    2037  
    2038       // check to see if the currently selected goto matches one these destinations 
    2039       if($dest['destination'] == $goto) $checked = true; 
    2040     } 
    2041  
    2042     // make a unique id to be used for the HTML id 
    2043     // This allows us to have multiple drawselect() sets on the page without 
    2044     // conflicting with each other 
    2045     $radioid = uniqid("drawselect"); 
    2046  
    2047     $cat_identifier = preg_replace('/[^a-zA-Z0-9]/','_', $cat); 
    2048  
    2049     // We bind to the hosting module's domain. If we find the translation there we use it, if not 
    2050     // we try the default 'amp' domain. If still no luck, we will try the _() which is the current 
    2051     // module's display since some old translation code may have stored it localy but should migrate 
    2052     // 
    2053     bindtextdomain($drawselects_module_hash[$cat],"modules/".$drawselects_module_hash[$cat]."/i18n"); 
    2054     bind_textdomain_codeset($drawselects_module_hash[$cat], 'utf8'); 
    2055     $label_text = dgettext($drawselects_module_hash[$cat],$cat); 
    2056     if ($label_text == $cat) { 
    2057       $label_text = dgettext('amp',$label_text); 
    2058     } 
    2059     if ($label_text == $cat) { 
    2060       $label_text = _($label_text); 
    2061     } 
    2062        
    2063     if ($tabindex_needed && ($checked || ! $goto)) { 
    2064       $tabindex_txt = (isset($tabindex) && $tabindex != '') ? ' tabindex="'.++$tabindex.'" ':''; 
    2065       $tabindex_needed = false; 
    2066     } else { 
    2067       $tabindex_txt = ''; 
    2068     } 
    2069     $selectHtml .=  '<input type="radio"'.$tabindex_txt.' id="'.$radioid.'" name="goto'.$i.'" value="'.$cat_identifier.'" '. 
    2070                     //'onclick="javascript:this.form.goto'.$i.'.value=\''.$cat.'\';" '. 
    2071                     //'onkeypress="javascript:if (event.keyCode == 0 || (document.all && event.keyCode == 13)) this.form.goto'.$i.'.value=\''.$cat.'\';" '. 
    2072                     ($checked? 'CHECKED=CHECKED' : '').' /> '; 
    2073     $selectHtml .= '<label for="'.$radioid.'">'.$label_text.':</label> '; 
     1986  global $tabindex, $active_modules, $drawselect_destinations, $drawselects_module_hash;  
     1987  $html=$destmod=$errorclass=$errorstyle=''; 
     1988 
     1989  if($table){$html.='<tr><td colspan=2>';}//wrap in table tags if requested 
     1990 
     1991  if(!isset($drawselect_destinations)){  
     1992    //check for module-specific destination functions 
     1993    foreach($active_modules as $rawmod => $module){ 
     1994      $funct = strtolower($rawmod.'_destinations'); 
    20741995     
    2075     // set the  
    2076 //    if ($checked) { $gotomod = $cat; }  
    2077  
    2078     $selectHtml .=  '<select name="'.$cat_identifier.$i.'" onfocus="document.getElementById(\''.$radioid.'\').checked = true; this.form.goto'.$i.'.value=\''.$cat.'\';">'; 
    2079     $selectHtml .= $options;   
    2080     $selectHtml .=  "</select><br />\n"; 
    2081  
    2082     if ($checked) $foundone = true; 
    2083   } 
    2084   /* --- MODULES END --- */ 
    2085    
    2086   // This is selected if $foundone is false (and goto is not blank) - basically, a fallback 
    2087   // The ONLY time no radio box is selected is if $goto is empty 
    2088   $custom_selected = !$foundone && !empty($goto); 
    2089    
    2090   //display a custom goto field 
    2091   if ($custom_selected || $show_custom) { 
    2092     if ($show_custom) { 
    2093       $custom_style = ""; 
    2094       $custom_background = ""; 
    2095     } else { 
    2096       $custom_style      = " style='color:red' "; 
    2097       $custom_background = " style='background:red' readonly='yes' "; 
    2098     } 
    2099     $radioid = uniqid("drawselect"); 
    2100     $selectHtml .= '<input type="radio" id="'.$radioid.'" name="goto'.$i.'" value="custom" '. 
    2101                  //'onclick="javascript:this.form.goto'.$i.'.value=\'custom\';" '. 
    2102            //'onkeypress="javascript:if (event.keyCode == 0 || (document.all && event.keyCode == 13)) this.form.goto'.$i.'.value=\'custom\';" '. 
    2103            ($custom_selected ? 'CHECKED=CHECKED' : '').' />'; 
    2104     $selectHtml .= '<a href="#" class="info" '.$custom_style.'>'._("Unknown Destination").'&nbsp;<span>'._("ERROR: You have an unknown destination. If this was carried over as a Custom App from an earlier version, you must go register the destination in the Custom Destination tab provided by the Custom Applications module.<br />This will remain active until you change it but you can no longer edit or add a new one here.").'</span></a>:'; 
    2105     $selectHtml .= '<input '.$custom_background.' type="text" size="15" name="custom'.$i.'" value="'.($custom_selected ? $goto : '').'" onfocus="document.getElementById(\''.$radioid.'\').checked = true;" />'; 
    2106  
    2107   //close off our row 
    2108   } 
    2109   if($table){ 
    2110     $selectHtml.='</td></tr>'; 
    2111   } 
    2112    
    2113   return $selectHtml; 
     1996      //if the modulename_destinations() function exits, run it and display selections for it 
     1997      if (function_exists($funct)) { 
     1998        $destArray = $funct(); //returns an array with 'destination' and 'description', and optionally 'category' 
     1999        if(is_Array($destArray)) { 
     2000          foreach($destArray as $dest){ 
     2001            $cat=(isset($dest['category'])?$dest['category']:$module['displayname']); 
     2002            $drawselect_destinations[$cat][] = $dest; 
     2003            $drawselects_module_hash[$cat] = $rawmod; 
     2004          } 
     2005        } 
     2006      } 
     2007    } 
     2008    //sort destination alphabeticaly     
     2009    ksort($drawselect_destinations); 
     2010    ksort($drawselects_module_hash); 
     2011  } 
     2012  //set varibales as arrays for the rare (imposible?) case where there are none 
     2013  if(!isset($drawselect_destinations)){$drawselect_destinations=array();} 
     2014  if(!isset($drawselects_module_hash)){$drawselects_module_hash = array();} 
     2015 
     2016  $foundone=false; 
     2017  $tabindex_needed=true; 
     2018  //get the destination module name if we have a $goto, add custom if there is an issue 
     2019  if($goto){ 
     2020    foreach($drawselects_module_hash as $mod => $description){ 
     2021      foreach($drawselect_destinations[$mod] as $destination){ 
     2022        if($goto==$destination['destination']){ 
     2023          $destmod=$mod; 
     2024      } 
     2025    } 
     2026  } 
     2027  if($destmod==''){//if we havnt found a match, display error dest 
     2028    $destmod='Error'; 
     2029    $drawselect_destinations['Error'][]=array('destination'=>$goto, 'description'=>'Bad Dest: '.$goto, 'class'=>'drawselect_error'); 
     2030    $drawselects_module_hash['Error']='error'; 
     2031  } 
     2032}  
     2033 
     2034  //draw "parent" select box 
     2035  $style=' style="'.(($destmod=='Error')?'background-color:red;':'background-color:white;').'"'; 
     2036  $html.='<select name="goto'.$i.'" class="destdropdown" '.$style.' tabindex="'.++$tabindex.'">'; 
     2037  $html.='<option value="" style="background-color:white;">== '._('chose one').' ==</option>'; 
     2038  foreach($drawselects_module_hash as $mod => $disc){ 
     2039    /* We bind to the hosting module's domain. If we find the translation there we use it, if not 
     2040     * we try the default 'amp' domain. If still no luck, we will try the _() which is the current 
     2041     * module's display since some old translation code may have stored it localy but should migrate */ 
     2042    bindtextdomain($drawselects_module_hash[$mod],"modules/".$drawselects_module_hash[$mod]."/i18n"); 
     2043    bind_textdomain_codeset($drawselects_module_hash[$mod], 'utf8'); 
     2044    $label_text=dgettext($drawselects_module_hash[$mod],$mod); 
     2045    if($label_text==$mod){$label_text=dgettext('amp',$label_text);} 
     2046    if($label_text==$mod){$label_text=_($label_text);} 
     2047    /* end i18n */ 
     2048    $selected=($mod==$destmod)?' SELECTED ':' '; 
     2049    $style=' style="'.(($mod=='Error')?'background-color:red;':'background-color:white;').'"'; 
     2050    $html.='<option value="'.str_replace(' ','_',$mod).'"'.$selected.$style.'>'.$mod.'</option>'; 
     2051  } 
     2052  $html.='</select> '; 
     2053   
     2054  //draw "children" select boxes 
     2055  $tabindexhtml=' tabindex="'.++$tabindex.'"';//keep out of the foreach so that we dont increment it 
     2056  foreach($drawselect_destinations as $cat=>$destination){ 
     2057    $style=(($cat==$destmod)?'':'display:none;'); 
     2058    if($cat=='Error'){$style.=' '.$errorstyle;}//add error style 
     2059    $style=' style="'.(($cat=='Error')?'background-color:red;':$style).'"'; 
     2060    $html.='<select name="'.str_replace(' ','_',$cat).$i.'" '.$tabindexhtml.$style.'>'; 
     2061    foreach($destination as $dest){ 
     2062      $selected=($goto==$dest['destination'])?'SELECTED ':' '; 
     2063      $style=' style="'.(($cat=='Error')?'background-color:red;':'background-color:white;').'"'; 
     2064      $html.='<option value="'.$dest['destination'].'" '.$selected.$style.'>'.$dest['description'].'</option>'; 
     2065    } 
     2066    $html.='</select>'; 
     2067  } 
     2068  if(isset($drawselect_destinations['Error'])){unset($drawselect_destinations['Error']);} 
     2069  if(isset($drawselects_module_hash['Error'])){unset($drawselects_module_hash['Error']);} 
     2070  if($table){$html.='</td></tr>';}//wrap in table tags if requested 
     2071   
     2072  return $html; 
    21142073} 
    21152074