Changeset 1813

Show
Ignore:
Timestamp:
05/02/06 13:00:45 (7 years ago)
Author:
rcourtna
Message:

big changes to module admin layout. should add years to the life of your mousing index finger!

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • freepbx/trunk/amp_conf/htdocs/admin/page.modules.php

    r1812 r1813  
    33$extdisplay = isset($_REQUEST['extdisplay'])?$_REQUEST['extdisplay']:''; 
    44 
    5 if (isset($_POST['submit'])) { // if form has been submitted 
    6   switch ($_POST['modaction']) { 
    7     case "install": 
    8       if (runModuleSQL($_POST['modname'],$_POST['modaction']))  
    9         installModule($_POST['modname'],$_POST['modversion']); 
    10       else 
    11         echo "<div class=\"error\">"._("Module install script failed to run")."</div>"; 
    12     break; 
    13     case "uninstall": 
    14       if (runModuleSQL($_POST['modname'],$_POST['modaction'])) 
    15         uninstallModule($_POST['modname']); 
    16       else 
    17         echo "<div class=\"error\">"._("Module uninstall script failed to run")."</div>"; 
    18        
    19     break; 
    20     case "enable": 
    21       enableModule($_POST['modname']); 
    22       //echo "<script language=\"Javascript\">document.location='".$_SERVER['PHP_SELF']."?".$_SERVER['QUERY_STRING']."&foo=1'</script>"; 
    23                         echo "<script language='Javascript'>window.location.reload()</script>\n";            
    24     break; 
    25     case "disable": 
    26       disableModule($_POST['modname']); 
    27       //echo "<script language=\"Javascript\">document.location='".$_SERVER['PHP_SELF']."?".$_SERVER['QUERY_STRING']."&foo=2'</script>"; 
    28                         echo "<script language='Javascript'>window.location.reload()</script>\n";            
    29     break; 
    30     case "delete": 
    31       deleteModule($_POST['modname']); 
    32     break; 
    33     case "download": 
    34       fetchModule($_POST['rawname']); 
    35     break; 
    36     case "upgrade": 
    37       upgradeModule($_POST['modname']); 
    38     break; 
    39     case "rmmod": 
    40       rmModule($_POST['modname']); 
    41     break; 
     5$installed = find_allmodules(); 
     6 
     7function pageReload(){ 
     8return ""; 
     9  //return "<script language=\"Javascript\">document.location='".$_SERVER['PHP_SELF']."?".$_SERVER['QUERY_STRING']."&foo=".rand()."'</script>"; 
     10
     11 
     12if (isset($_POST['submit']) && is_array($_POST['modules'])) { // if form has been submitted 
     13  foreach ($_POST['modules'] as $module) { 
     14    switch ($_POST['modaction']) { 
     15      case "install": 
     16        if (runModuleSQL($module,'install'))  
     17          installModule($module,$_POST[$module.'_version']); 
     18        else 
     19          echo "<div class=\"error\">"._("Module install script failed to run")."</div>"; 
     20      break; 
     21      case "uninstall": 
     22        if (runModuleSQL($module,'uninstall')) 
     23          uninstallModule($module); 
     24        else 
     25          echo "<div class=\"error\">"._("Module uninstall script failed to run")."</div>"; 
     26      break; 
     27      case "enable": 
     28        enableModule($module); 
     29        echo pageReload(); 
     30      break; 
     31      case "disable": 
     32        disableModule($module); 
     33        echo pageReload(); 
     34      break; 
     35      case "delete": 
     36        deleteModule($module); 
     37        rmModule($module); 
     38      break; 
     39      case "download": 
     40        fetchModule($module); 
     41      break; 
     42      case "upgrade": 
     43        upgradeModule($module); 
     44      break; 
     45      case "installenable": // install and enable a module 
     46        $boolInstall = true; 
     47        // only run install if it's not installed 
     48        if ($installed[$module]['status'] == 0) { 
     49          // set to false on failed install 
     50          $boolInstall = runModuleSQL($module,'install'); 
     51          if ($boolInstall) { 
     52            installModule($module,$_POST[$module.'_version']); 
     53            enableModule($module); 
     54            echo pageReload(); 
     55          } else { 
     56            echo "<div class=\"error\">{$module}: "._("Module install script failed to run")."</div>"; 
     57          } 
     58        } else { // it's already installed, so just enable it 
     59          enableModule($module); 
     60          echo pageReload(); 
     61        } 
     62      break; 
     63      case "downloadinstall": // download, install and enable 
     64        fetchModule($module); 
     65        if (runModuleSQL($module,'install'))  
     66          installModule($module,$_POST[$module.'_version']); 
     67        else 
     68          echo "<div class=\"error\">"._("Module install script failed to run")."</div>"; 
     69        enableModule($module); 
     70      break; 
     71      case "downloadupdate": //download and update 
     72        fetchModule($module); 
     73        upgradeModule($module); 
     74      break; 
     75      case "uninstalldelete": //uninstall and delete 
     76        if (runModuleSQL($module,'uninstall')) 
     77          uninstallModule($module); 
     78        else 
     79          echo "<div class=\"error\">"._("Module uninstall script failed to run")."</div>"; 
     80        deleteModule($module); 
     81        rmModule($module); 
     82      break; 
     83    } 
    4284  } 
    4385} 
     
    5799  case "online":  
    58100    echo "<h2>"; 
    59     echo _("Online Modules"); 
     101    echo _("Module Administration (online)"); 
    60102    echo "</h2>"; 
    61     echo "<h3><a href='config.php?display=modules&type=tool&extdisplay=local'>"._("Local Modules")."</a></h3>\n"; 
     103    echo "<a href='config.php?display=modules&type=tool&extdisplay=local'>"._("Terminate Connection to Online Module Repository")."</a>\n"; 
    62104    // determine which modules we have installed already 
    63105    $installed = find_allmodules(); 
     
    69111  default: 
    70112    echo "<h2>"; 
    71     echo _("Local Module Administration"); 
     113    echo _("Module Administration"); 
    72114    echo "</h2>"; 
    73     echo "<h3><a href='config.php?display=modules&type=tool&extdisplay=online'>"._("Online Modules")."</a></h3>\n"; 
     115    echo "<a href='config.php?display=modules&type=tool&extdisplay=online'>"._("Connect to Online Module Repository")."</a>\n"; 
    74116    $installed = find_allmodules(); 
    75117    $dispMods = new displayModules($installed); 
     
    134176          // version_compare returns 1 if new > old 
    135177          if (version_compare($newversion,$oldversion) == 1) { 
    136             $status = "Local (update available)"; 
    137             $action = " 
    138             <form action={$_SERVER['PHP_SELF']}?{$_SERVER['QUERY_STRING']} method=post> 
    139               <input type=hidden name=modaction value=download> 
    140               <input type=hidden name=rawname value={$online[$arrkey]['rawname']}> 
    141               <input type=submit name=submit value=Download> 
    142             </form> 
    143             "; 
     178            $modsOnlineUpdate[] = $online[$arrkey]; 
    144179          } else { 
    145             $status = "Local (up to date)"; 
    146             $action = ""
     180            // we are not displaying this array .. it's just here for kicks 
     181            $modsOnlineInstalled[] = $online[$arrkey]
    147182          } 
    148183        } else { 
    149           $status = "Online"; 
    150           $action = " 
    151           <form action={$_SERVER['PHP_SELF']}?{$_SERVER['QUERY_STRING']} method=post> 
    152             <input type=hidden name=modaction value=download> 
    153             <input type=hidden name=rawname value={$online[$arrkey]['rawname']}> 
    154             <input type=submit name=submit value=Download> 
    155           </form> 
     184          $modsOnlineOnly[] = $online[$arrkey]; 
     185        } 
     186         
     187        //$this->html .= $this->tableHtml($online[$arrkey],$status,$action); 
     188      } 
     189       
     190      /*  
     191       *  Available Module Updates 
     192       */ 
     193      if(is_array($modsOnlineUpdate)) { 
     194        $rows = ""; 
     195        foreach($modsOnlineUpdate as $mod) { 
     196          $color = "orange"; 
     197          $rows .= $this->tableHtml($mod,$color); 
     198        } 
     199        $this->options = " 
     200          <select name=\"modaction\"> 
     201            <option value=\"downloadupdate\">"._("Download and Update selected")." 
     202            <option value=\"download\">"._("Download selected")." 
     203          </select> 
     204          <input type=\"submit\" name=\"submit\" value=\""._("Submit")."\"> 
    156205          "; 
    157         } 
    158          
    159         $this->html .= $this->tableHtml($online[$arrkey],$status,$action); 
    160       } 
    161        
    162     } else {  //local modules 
    163        
    164       $installed = $this->sortModules($installed); 
    165       if (isset($installed) && is_array($installed)) { 
    166         foreach($installed as $key => $mod) { 
    167           //dynamicatlly create a form based on status 
    168           if ($mod['status'] == 0) { 
    169             $status = _("Not Installed"); 
    170             //install form 
    171             $action = "<form method=\"POST\" action=\"{$_SERVER['REQUEST_URI']}\" style=display:inline>"; 
    172             $action .= "<input type=\"hidden\" name=\"modname\" value=\"{$key}\">"; 
    173             $action .= "<input type=\"hidden\" name=\"modversion\" value=\"{$mod['version']}\">"; 
    174             $action .= "<input type=\"hidden\" name=\"modaction\" value=\"install\">"; 
    175             $action .= "<input type=\"submit\" name=\"submit\" value=\""._("Install")."\">"; 
    176             $action .= "</form>"; 
    177             $action .= "<form method=\"POST\" action=\"{$_SERVER['REQUEST_URI']}\" style=display:inline>"; 
    178             $action .= "<input type=\"hidden\" name=\"modname\" value=\"{$key}\">"; 
    179             $action .= "<input type=\"hidden\" name=\"modversion\" value=\"{$mod['version']}\">"; 
    180             $action .= "<input type=\"hidden\" name=\"modaction\" value=\"rmmod\">"; 
    181             $action .= "<input type=\"submit\" name=\"submit\" value=\""._("Remove")."\">"; 
    182             $action .= "</form>"; 
    183           } else if($mod['status'] == 1){ 
    184             $status = _("Disabled"); 
    185             //enable form 
    186             $action = "<form method=\"POST\" action=\"{$_SERVER['REQUEST_URI']}\" style=display:inline>"; 
    187             $action .= "<input type=\"hidden\" name=\"modname\" value=\"{$key}\">"; 
    188             $action .= "<input type=\"hidden\" name=\"modaction\" value=\"enable\">"; 
    189             $action .= "<input type=\"submit\" name=\"submit\" value=\""._("Enable")."\">"; 
    190             $action .= "</form>"; 
    191             //uninstall form 
    192             $action .= "<form method=\"POST\" action=\"{$_SERVER['REQUEST_URI']}\" style=display:inline>"; 
    193             $action .= "<input type=\"hidden\" name=\"modname\" value=\"{$key}\">"; 
    194             $action .= "<input type=\"hidden\" name=\"modaction\" value=\"uninstall\">"; 
    195             $action .= "<input type=\"submit\" name=\"submit\" value=\""._("Uninstall")."\">"; 
    196             $action .= "</form>"; 
    197              
    198           } else if($mod['status'] == 2){ 
    199             $status = _("Enabled"); 
    200             //disable form 
    201             $action = "<form method=\"POST\" action=\"{$_SERVER['REQUEST_URI']}\" style=display:inline>"; 
    202             $action .= "<input type=\"hidden\" name=\"modname\" value=\"{$key}\">"; 
    203             $action .= "<input type=\"hidden\" name=\"modaction\" value=\"disable\">"; 
    204             $action .= "<input type=\"submit\" name=\"submit\" value=\""._("Disable")."\">"; 
    205             $action .= "</form>"; 
    206           } else if($mod['status'] == 3){ 
    207             $status = _("Enabled (needs update)"); 
    208             //disable form 
    209             $action = "<form method=\"POST\" action=\"{$_SERVER['REQUEST_URI']}\" style=display:inline>"; 
    210             $action .= "<input type=\"hidden\" name=\"modname\" value=\"{$key}\">"; 
    211             $action .= "<input type=\"hidden\" name=\"modaction\" value=\"disable\">"; 
    212             $action .= "<input type=\"submit\" name=\"submit\" value=\""._("Disable")."\">"; 
    213             $action .= "</form>"; 
    214             //upgrade form 
    215             $action .= "<form method=\"POST\" action=\"{$_SERVER['REQUEST_URI']}\" style=display:inline>"; 
    216             $action .= "<input type=\"hidden\" name=\"modname\" value=\"{$key}\">"; 
    217             $action .= "<input type=\"hidden\" name=\"modversion\" value=\"{$mod['version']}\">"; 
    218             $action .= "<input type=\"hidden\" name=\"modaction\" value=\"upgrade\">"; 
    219             $action .= "<input type=\"submit\" name=\"submit\" value=\""._("Update")."\">"; 
    220             $action .= "</form>"; 
    221           } else if($mod['status'] == -1){ 
    222             $status = _("Broken"); 
    223             //disable form 
    224             $action = "<form method=\"POST\" action=\"{$_SERVER['REQUEST_URI']}\" style=display:inline>"; 
    225             $action .= "<input type=\"hidden\" name=\"modname\" value=\"{$key}\">"; 
    226             $action .= "<input type=\"hidden\" name=\"modaction\" value=\"delete\">"; 
    227             $action .= "<input type=\"submit\" name=\"submit\" value=\""._("Delete")."\">"; 
    228             $action .= "</form>"; 
    229           } 
    230           $this->html .= $this->tableHtml($mod,$status,$action); 
    231         } 
    232       } 
    233     } 
     206        // build the table 
     207        $this->html .= $this->formStart(_("Available Module Updates (online)")); 
     208        $this->html .= $rows; 
     209        $this->html .= $this->formEnd($mod['status']); 
     210      } 
     211       
     212      /*  
     213       *  Online Modules 
     214       */      
     215      if(is_array($modsOnlineOnly)) { 
     216        $rows = ""; 
     217        foreach($modsOnlineOnly as $mod) { 
     218          $color = "white"; 
     219          $rows .= $this->tableHtml($mod,$color); 
     220        } 
     221        $this->options = " 
     222          <select name=\"modaction\"> 
     223            <option value=\"downloadinstall\">"._("Download and Install selected")." 
     224            <option value=\"download\">"._("Download selected")." 
     225          </select> 
     226          <input type=\"submit\" name=\"submit\" value=\""._("Submit")."\"> 
     227          "; 
     228        // build the table 
     229        $this->html .= $this->formStart(_("Modules Available (online)")); 
     230        $this->html .= $rows; 
     231        $this->html .= $this->formEnd($mod['status']); 
     232      }      
     233       
     234    } 
     235       
     236    $installed = $this->sortModules($installed); 
     237    if (isset($installed) && is_array($installed)) { 
     238      foreach($installed as $mod) { 
     239        //create seperate arrays based on module status 
     240        if ($mod['status'] == 0) { 
     241          $modsNotinstalled[] = $mod; 
     242        } else if($mod['status'] == 1){ 
     243          $modsDisabled[] = $mod; 
     244        } else if($mod['status'] == 2){ 
     245          $modsEnabled[] = $mod; 
     246        } else if($mod['status'] == 3){ 
     247          $modsUpdate[] = $mod; 
     248        } else if($mod['status'] == -1){ 
     249          $modsBroken[] = $mod; 
     250        } 
     251 
     252        //$this->html .= $this->tableHtml($mod,$status,$color); 
     253      } 
     254       
     255      // draw a form and list for each module status 
     256      /*  
     257       *  Modules Needing Update 
     258       */ 
     259      if(is_array($modsUpdate)) { 
     260        $rows = ""; 
     261        foreach($modsUpdate as $mod) {     
     262          $color = "#CCFF00"; 
     263          $rows .= $this->tableHtml($mod,$color); 
     264        } 
     265        $this->options = " 
     266          <select name=\"modaction\"> 
     267            <option value=\"upgrade\">"._("Upgrade Selected")." 
     268          </select> 
     269          <input type=\"submit\" name=\"submit\" value=\""._("Submit")."\"> 
     270          "; 
     271        // build the table 
     272        $this->html .= $this->formStart(_("Enabled Modules Requiring Upgrade")); 
     273        $this->html .= $rows; 
     274        $this->html .= $this->formEnd($mod['status']); 
     275      } 
     276       
     277      /*  
     278       *  Enabled Modules 
     279       */      
     280      if(is_array($modsEnabled)) { 
     281        $rows = ""; 
     282        foreach($modsEnabled as $mod) { 
     283          $color = "white"; 
     284          $rows .= $this->tableHtml($mod,$color); 
     285        } 
     286        $this->options = " 
     287          <select name=\"modaction\"> 
     288            <option value=\"disable\">"._("Disable Selected")." 
     289            <option value=\"uninstall\">"._("Uninstall Selected")." 
     290            <option value=\"uninstalldelete\">"._("Uninstall and Delete Selected")." 
     291          </select> 
     292          <input type=\"submit\" name=\"submit\" value=\""._("Submit")."\"> 
     293          "; 
     294        // build the table 
     295        $this->html .= $this->formStart(_("Enabled Modules")); 
     296        $this->html .= $rows; 
     297        $this->html .= $this->formEnd($mod['status']); 
     298      } 
     299       
     300      /*  
     301       *  Disabled Modules 
     302       */      
     303      if(is_array($modsDisabled)) { 
     304        $rows = ""; 
     305        foreach($modsDisabled as $mod) { 
     306          $color = "white"; 
     307          $rows .= $this->tableHtml($mod,$color); 
     308        } 
     309        $this->options = " 
     310          <select name=\"modaction\"> 
     311            <option value=\"enable\">"._("Enable Selected")." 
     312            <option value=\"uninstall\">"._("Uninstall Selected")." 
     313            <option value=\"uninstalldelete\">"._("Uninstall and Delete Selected")." 
     314          </select> 
     315          <input type=\"submit\" name=\"submit\" value=\""._("Submit")."\"> 
     316          "; 
     317        // build the table 
     318        $this->html .= $this->formStart(_("Disabled Modules")); 
     319        $this->html .= $rows; 
     320        $this->html .= $this->formEnd($mod['status']); 
     321      } 
     322 
     323      /*  
     324       *  Local Modules Not Installed 
     325       */      
     326      if(is_array($modsNotinstalled)) { 
     327        $rows = ""; 
     328        foreach($modsNotinstalled as $mod) { 
     329          $color = "white"; 
     330          $rows .= $this->tableHtml($mod,$color); 
     331        } 
     332        $this->options = " 
     333          <select name=\"modaction\"> 
     334            <option value=\"installenable\">"._("Enable Selected")." 
     335            <option value=\"delete\">"._("Delete Selected")." 
     336          </select> 
     337          <input type=\"submit\" name=\"submit\" value=\""._("Submit")."\"> 
     338          "; 
     339        // build the table 
     340        $this->html .= $this->formStart(_("Not Installed Local Modules")); 
     341        $this->html .= $rows; 
     342        $this->html .= $this->formEnd($mod['status']); 
     343      } 
     344       
     345      if(is_array($modsBroken)) { 
     346        $rows = ""; 
     347        foreach($modsBroken as $mod) { 
     348          $color = "#FFFFFF"; 
     349          $rows .= $this->tableHtml($mod,$color); 
     350        } 
     351        $this->options = " 
     352          <select name=\"modac 
     353            <option value=\"delete\">"._("Delete Selected")." 
     354          </select> 
     355          <input type=\"submit\" name=\"submit\" value=\""._("Submit")."\"> 
     356          "; 
     357        // build the table 
     358        $this->html .= $this->formStart(_('Broken')); 
     359        $this->html .= $rows; 
     360        $this->html .= $this->formEnd($mod['status']); 
     361      } 
     362       
     363    } 
     364     
    234365  } 
    235366   
     
    263394  } 
    264395   
    265   function tableHtml($arrRow,$status,$action) { 
     396  function tableHtml($arrRow,$color) { 
    266397    return <<< End_of_Html 
    267398       
    268       <tr> 
     399      <tr bgcolor={$color}> 
     400        <td> 
     401          <input type="checkbox" name="modules[]" value="{$arrRow['rawname']}"> 
     402          <input type="hidden" name="{$arrRow['rawname']}_version" value="{$arrRow['version']}"> 
     403        </td> 
    269404        <td><a target=_BLANK href={$arrRow['info']}>{$arrRow['displayName']} ({$arrRow['rawname']})</a></td> 
    270405        <td>{$arrRow['version']}</td> 
    271406        <td>{$arrRow['type']}</td> 
    272407        <td>{$arrRow['category']}</td> 
    273         <td>{$status}</td> 
    274         <td>{$action}</td> 
    275408      </tr> 
    276409       
     
    278411  } 
    279412   
     413  function formStart($title = "") { 
     414    return " 
     415      <h4>{$title}</h4> 
     416      <form method=\"POST\" action=\"{$_SERVER['REQUEST_URI']}\"> 
     417      <table border=1><tr><th>&nbsp;</th><th>". _("Module")."</th><th>". _("Version")."</th><th>". _("Type") ."</th><th>". _("Category") ."</th></tr> 
     418        "; 
     419  } 
     420 
     421  function formEnd() { 
     422    return "</table>{$this->options}</form><hr>"; 
     423  } 
     424     
    280425  function drawModules() { 
    281     $table = "<table border=1><tr><th>". _("Module")."</th><th>". _("Version")."</th><th>". _("Type") ."</th><th>". _("Category") ."</th><th>". _("Status") ."</th><th>". _("Action") ."</th></tr>"; 
    282     $table .= $this->html; 
    283       $table .= "</table>"; 
    284     return $table; 
     426    return $this->html; 
    285427  } 
    286428} 
     
    329471  $retval = false; 
    330472  // if there is an sql file, run it 
    331   if (is_file("{$amp_conf['AMPWEBROOT']}/admin/modules/{$moddir}/{$type}.sql")) { 
     473  if (is_file("modules/{$moddir}/{$type}.sql")) { 
    332474    // run sql script 
    333     $fd = fopen("{$amp_conf['AMPWEBROOT']}/admin/modules/{$moddir}/{$type}.sql","r"); 
     475    $fd = fopen("modules/{$moddir}/{$type}.sql","r"); 
    334476    while (!feof($fd)) { 
    335477      $data .= fread($fd, 1024); 
     
    349491   
    350492  // if there is a php file, run it 
    351   if (is_file("{$amp_conf['AMPWEBROOT']}/admin/modules/{$moddir}/{$type}.php")) { 
    352     include("{$amp_conf['AMPWEBROOT']}/admin/modules/{$moddir}/{$type}.php"); 
     493  if (is_file("modules/{$moddir}/{$type}.php")) { 
     494    include("modules/{$moddir}/{$type}.php"); 
    353495    $retval = true; 
    354496  }