function system_modules_form

7.x system.module system_modules_form()
6.x system.module system_modules_form()
4.x system.module system_modules_form()
5.x system.module system_modules_form()

This is the form which an admin may use to manage the modules in the system.

File

modules/system/system.module, line 4386

Code

function system_modules_form() {
  $form = array();
  $m = 0;

  fp_add_css(fp_get_module_path("system") . "/css/style.css");

  $form ["mark" . $m++] = array(
    "value" => t("Use this form to enable or disable modules.  This scans the /modules/ and then /custom/modules/
                  directories.") . " 
                  " . l(t("Run DB updates?"), "admin/db-updates") . "<br><br>",
  );


  // Begin by scanning the /modules/ directory.  Anything in there
  // cannot be disabled.
  $module_dirs = array();
  $module_dirs [] = array("start" => "modules", "type" => t("Core"));
  $module_dirs [] = array("start" => "custom/modules", "type" => t("Custom"));
  // We will also add any directories which begin with an underscore in the custom/modules directory.
  // For example:   custom/modules/_contrib
  // Let's find such directories now.
  $dir_files = scandir("custom/modules");
  foreach ($dir_files as $file) {
    if ($file == '.' || $file == '..') {
      continue;
    }
    if (substr($file, 0, 1) == '_' && is_dir("custom/modules/$file")) {
      $module_dirs [] = array("start" => "custom/modules/$file", "type" => t("Custom/$file"));
    }
  }



  foreach ($module_dirs as $module_dir) {
    $start_dir = $module_dir ["start"];

    if ($dh = opendir($start_dir)) {
      //$pC .= "<div class='fp-system-modules-type'>{$module_dir["type"]}</div>
      //        <table class='fp-system-modules-table' cellpadding='0' cellspacing='0'>";

      $form ["mark" . $m++] = array(
        "value" => "<div class='fp-system-modules-type'>{$module_dir ["type"]}</div>
                    <table class='fp-system-modules-table' cellpadding='0' cellspacing='0'>",
      );


      $pol = "even";
      $dir_files = scandir($start_dir);
      foreach ($dir_files as $file) {
        if ($file == "." || $file == "..") {
          continue;
        }

        if (is_dir($start_dir . "/" . $file)) {

          // Okay, now look inside and see if there is a .info file.
          if (file_exists("$start_dir/$file/$file.info")) {
            $module = $file;
            $info_contents = file_get_contents("$start_dir/$file/$file.info");


            // From the info_contents variable, split up and place into an array.
            $info_details_array = array("path" => "", "module" => "",
              "schema" => "", "core" => "", "description" => "",
              "requires" => "", "version" => "",
              "required" => "",);

            $lines = explode("\n", $info_contents);
            foreach ($lines as $line) {
              if (trim($line) == "") {
                continue;
              }
              $temp = explode("=", trim($line));
              $info_details_array [trim($temp [0])] = trim(substr($line, strlen($temp [0]) + 1));
            }


            $path = "$start_dir/$file";

            $info_details_array ["path"] = $path;
            $info_details_array ["module"] = $module;


            // Expected keys:
            // name, description, version, core, requires (csv), requred (true or false)
            $checked = "";

            $form ["mark" . $m++] = array(
              "value" => "<tr class='fp-system-modules-row fp-system-modules-row-$pol'>
                            <td width='35%'>",
            );

            // the Checkbox.            
            // Should it be checked?  We can check the modules table to see if it's enabled/installed or not.
            $installation_status = "";
            $default_value = array();
            $res = db_query("SELECT * FROM modules WHERE path = '?' ", $path);
            $cur = db_fetch_array($res);
            if ($cur) {
              $info_details_array ["enabled"] = $cur ["enabled"];
              if ($cur ["enabled"] == "1") {
                // Yes, it is checked!
                $default_value = array($module => $module);
              }
              else if ($cur ["enabled"] == "") {
                $installation_status = t("not installed");
              }
              else if ($cur ["enabled"] == "0") {
                $installation_status = fp_get_js_confirm_link(t("Are you sure you wish to uninstall @module?\\nThis may remove saved data belonging to the module.", array("@module" => $module)), 
                ' window.location="' . fp_url("system/uninstall-module", "module=$module&path=" . urlencode($path) . "") . '"; ', t("uninstall?"));
              }


              // Does this module need to run db updates?
              if ($cur ["enabled"] == "1" && $cur ["schema"] != $info_details_array ["schema"] && $info_details_array ["schema"] != "") {
                $installation_status = "<b>" . l(t("Run db updates"), "admin/db-updates") . "</b>";

                // Let's also make sure to enable a message at the top of the screen, letting the user
                // know that there are needed updates.
                fp_add_message("<b>" . t("Note:") . "</b> " . t("There are modules which have been updated.  Please back up your database,
                                  then run the DB Updates function below as soon as possible."), "error", TRUE);
              }

            }


            $attributes = array();
            if ($info_details_array ["required"]) {
              // This is a required module; it cannot be unchecked.
              $attributes ["disabled"] = "disabled";
            }

            $bool_overriding = FALSE;
            // Did this module already exist in $form?  In other words,
            // is the module overriding a core module?  If so, we need to know
            // so we can display something special.
            if (isset($form ["cb__$module"])) {
              $bool_overriding = TRUE;
            }

            $requires = "";

            // If this module requires a higher core version of FlightPath than what we
            // are running, disable and explain to the user.
            if (FLIGHTPATH_VERSION != '%FP_VERSION%' && $info_details_array ["requires core version"]) {
              // Test to see if the current version is >= to the required core version.
              if (version_compare(FLIGHTPATH_VERSION, $info_details_array ["requires core version"], "<")) {
                // No, it's LESS than the required version!  We shouldn't be able to use this module!
                $attributes ["disabled"] = "disabled";
                $requires .= "<div style='color: red;'>" . t("This module requires
                                          that you run FlightPath version %fpv or higher.  
                                          You are instead running version %fpov.  Please update
                                          your core copy of FlightPath before attempting to install this
                                          module.", array('%fpv' => $info_details_array ["requires core version"],
                  '%fpov' => FLIGHTPATH_VERSION)) . "</div>";
              }
            }


            // Let's see if this module is for the wrong core entirely.
            if ($info_details_array ["core"]) {

              // Test to see if we are not the correct core version.
              if (strtolower(FLIGHTPATH_CORE) != strtolower($info_details_array ["core"])) {
                // Nope, the wrong core version!
                $attributes ["disabled"] = "disabled";
                $requires .= "<div style='color: red;'>" . t("This module requires
                                          that you run FlightPath core version %fpv.  
                                          You are instead running version %fpov.  Please either download
                                          the correct version of this module for your FlightPath core version,
                                          or update FlightPath to the required core version.", array('%fpv' => $info_details_array ["core"],
                  '%fpov' => FLIGHTPATH_CORE)) . "</div>";
              }
            }




            $form ["cb__$module"] = array(
              "type" => "checkboxes",
              "options" => array($module => $info_details_array ["name"]),
              "value" => $default_value,
              "suffix" => "<div class='fp-system-modules-machine-name'>$file</div>
                            <div class='fp-system-modules-installation-status'>$installation_status</div>
                            ",
              "attributes" => $attributes,
            );

            // hidden variable containing the details about this module, for later use on submit.
            $form ["module_details__$module"] = array(
              "type" => "hidden",
              "value" => urlencode(serialize($info_details_array)),
            );



            // Version & descr.            
            if ($info_details_array ["requires"] != "") {
              $requires .= "<div class='fp-system-modules-requires hypo'>
                            <b>" . t("Requires:") . "</b> {$info_details_array ["requires"]}
                           </div>";

            }

            // if we are overriding a module, then display something special.
            if ($bool_overriding) {
              $form ["mark" . $m++] = array(
                "value" => "<em>" . t("Overriding core module:") . "<br>{$info_details_array ["name"]}</em>
                            <div class='fp-system-modules-machine-name'>$file</div>
                            <div class='fp-system-modules-installation-status'>
                            " . t("Use checkbox in Core section above to manage module") . "
                            </div>",
              );
            }

            $form ["mark" . $m++] = array(
              "value" => "  </td>
                            <td width='5%' >{$info_details_array ["version"]}</td>
                            <td >{$info_details_array ["description"]}$requires</td>
                          </tr>
                          ",

            );


            $pol = ($pol == "even") ? "odd" : "even";

          } // if file_exists (info file)        
        } // if is_dir      
      } // while file=readdir

      $form ["mark" . $m++] = array(
        "value" => "</table>",
      );

    } // if opendir($startdir)
  }
  // foreach moduledirs

  $form ["submit"] = array(
    "type" => "submit",
    "spinner" => TRUE,
    "value" => t("Submit"),
    "prefix" => "<hr>",
  );


  return $form;
}