From 4dc69829a238d48ae936c1c980ea497353ad8018 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?C=C3=B4me=20Bernigaud?= <come.bernigaud@opensides.be>
Date: Wed, 3 Sep 2014 13:30:44 +0200
Subject: [PATCH] Fixes #2919 Finished migrating setup to simplePlugin

---
 setup/class_setup.inc             |  3 +-
 setup/class_setupStep.inc         | 99 -------------------------------
 setup/class_setupStep_Finish.inc  | 76 +++++++++++++-----------
 setup/class_setupStep_Migrate.inc |  2 +-
 setup/setup_finish.tpl            |  6 +-
 setup/setup_migrate.tpl           | 20 +++----
 6 files changed, 54 insertions(+), 152 deletions(-)

diff --git a/setup/class_setup.inc b/setup/class_setup.inc
index 1304cb90f..936f90578 100644
--- a/setup/class_setup.inc
+++ b/setup/class_setup.inc
@@ -1,9 +1,8 @@
 <?php
-
 /*
   This code is part of FusionDirectory (http://www.fusiondirectory.org/)
   Copyright (C) 2003  Cajus Pollmeier
-  Copyright (C) 2011-2013  FusionDirectory
+  Copyright (C) 2011-2014  FusionDirectory
 
   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
diff --git a/setup/class_setupStep.inc b/setup/class_setupStep.inc
index 1d134b7b9..a57ce3d51 100644
--- a/setup/class_setupStep.inc
+++ b/setup/class_setupStep.inc
@@ -133,103 +133,4 @@ class setupStep extends simplePlugin
     return $ldap;
   }
 }
-
-class setup_step extends plugin
-{
-  var $s_title      = "Still undefined";
-  var $s_title_long = "This is a still undefined long title";
-  var $s_info       = "This info is still undefined. This setup step detect the type of your ldap for FusionDirectory.This is a basic requirement for fusiondirectory.";
-  var $is_active    = FALSE;
-  var $is_enabled   = FALSE;
-  var $is_completed = FALSE;
-
-  var $header_image = "";
-
-  var $attributes   = array();
-  var $parent       = NULL;
-  var $dialog       = FALSE;
-
-  function __construct()
-  {
-  }
-
-  function execute()
-  {
-  }
-
-  function save_object()
-  {
-    /* Do not call plugin::save_object. This causes acl trouble  */
-  }
-
-  function get_title()
-  {
-    return $this->s_title;
-  }
-
-  function get_long_title()
-  {
-    return $this->s_title_long;
-  }
-
-  function get_small_info()
-  {
-    return $this->s_info;
-  }
-
-  function is_active()
-  {
-    return $this->is_active;
-  }
-
-  function is_enabled()
-  {
-    return $this->is_enabled;
-  }
-
-  function is_completed()
-  {
-    return $this->is_completed;
-  }
-
-  function set_active($value = TRUE)
-  {
-    $this->is_active = ($value == TRUE);
-  }
-
-  function set_enabled($value = TRUE)
-  {
-    $this->is_enabled = ($value == TRUE);
-  }
-
-  function set_completed($value = TRUE)
-  {
-    $this->is_completed = ($value == TRUE);
-  }
-
-  /* Return attributes handled by this setup step */
-  function get_attributes()
-  {
-    $tmp = array();
-    foreach ($this->attributes as $attr) {
-      $tmp[$attr] = $this->$attr;
-    }
-    return $tmp;
-  }
-
-  function get_ldap_link()
-  {
-    /* Establish ldap connection */
-    $cv = $this->parent->captured_values;
-    $ldap_l = new LDAP($cv['admin'],
-        $cv['password'],
-        $cv['connection'],
-        FALSE,
-        $cv['tls']);
-
-    $ldap = new ldapMultiplexer($ldap_l);
-    $ldap->cd($cv['base']);
-    return $ldap;
-  }
-}
 ?>
diff --git a/setup/class_setupStep_Finish.inc b/setup/class_setupStep_Finish.inc
index 55651b266..892c5f4d8 100644
--- a/setup/class_setupStep_Finish.inc
+++ b/setup/class_setupStep_Finish.inc
@@ -2,7 +2,7 @@
 /*
   This code is part of FusionDirectory (http://www.fusiondirectory.org/)
   Copyright (C) 2007  Fabian Hickert
-  Copyright (C) 2011-2013  FusionDirectory
+  Copyright (C) 2011-2014  FusionDirectory
 
   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
@@ -19,28 +19,35 @@
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
 */
 
-class Step_Finish extends setup_step
+class Step_Finish extends setupStep
 {
-  var $header_image = "geticon.php?context=devices&icon=server&size=48";
+  var $header_image = 'geticon.php?context=devices&icon=server&size=48';
 
-  function __construct()
+  static function getAttributesInfo()
   {
-    $this->update_strings();
+    return array(
+      'welcome' => array(
+        'name'      => _('Welcome'),
+        'template'  => get_template_path("setup_finish.tpl", TRUE, dirname(__FILE__)),
+        'attrs'     => array(
+        )
+      )
+    );
   }
 
   function update_strings()
   {
-    $this->s_title      = _("Finish");
-    $this->s_info       = _("Write configuration file");
-    $this->s_title_long = _("Finish - write the configuration file");
+    $this->s_title      = _('Finish');
+    $this->s_info       = _('Write configuration file');
+    $this->s_title_long = _('Finish - write the configuration file');
   }
 
   function get_conf_data()
   {
     $smarty = get_smarty();
-    $smarty->assign("cv",                       xmlentities($this->parent->captured_values));
-    $smarty->assign("config_checksum",          md5(file_get_contents(CONFIG_TEMPLATE_DIR.CONFIG_FILE)));
-    $smarty->assign("templateCompileDirectory", SPOOL_DIR);
+    $smarty->assign('cv',                       xmlentities($this->parent->captured_values));
+    $smarty->assign('config_checksum',          md5(file_get_contents(CONFIG_TEMPLATE_DIR.CONFIG_FILE)));
+    $smarty->assign('templateCompileDirectory', SPOOL_DIR);
     return $smarty->fetch(CONFIG_TEMPLATE_DIR.CONFIG_FILE);
   }
 
@@ -74,43 +81,43 @@ class Step_Finish extends setup_step
 
   function execute()
   {
-    global $BASE_DIR;
-
     /* Check if there is currently an active fusiondirectory.conf */
-    $exists = file_exists(CONFIG_DIR."/".CONFIG_FILE);
+    $exists   = file_exists(CONFIG_DIR."/".CONFIG_FILE);
+    $err_msg  = '';
+
+    if ($exists && $this->is_world_readable(CONFIG_DIR.'/'.CONFIG_FILE)) {
+      $err_msg = _('Your configuration file is currently world readable. Please update the file permissions!');
+    } elseif (!$exists) {
+      $err_msg = _('The configuration is currently not readable or it does not exists.');
+    }
+
+    $smarty = get_smarty();
+    $smarty->assign('err_msg',  $err_msg);
+    $smarty->assign('msg2',     sprintf(_('After downloading and placing the file under %s, please make sure that the user the webserver is running with is able to read %s, while other users shouldn\'t.'), CONFIG_DIR, CONFIG_FILE));
+
+    return parent::execute();
+  }
+
+  function save_object()
+  {
+    parent::save_object();
+    $exists = file_exists(CONFIG_DIR.'/'.CONFIG_FILE);
 
     /* Redirect to FusionDirectory login, if :
      *   - fusiondirectory.conf exists
      *   - Permisssion are set correctly
      */
-
-    if (isset($_POST['next']) && $exists && !$this->is_world_readable(CONFIG_DIR."/".CONFIG_FILE)) {
+    if (isset($_POST['next']) && $exists && !$this->is_world_readable(CONFIG_DIR.'/'.CONFIG_FILE)) {
       $this->insertConfigDefaults();
       session::destroy();
-      header("Location: index.php");
+      header('Location: index.php');
       exit();
     }
 
     /* Download config */
     if (isset($_POST['getconf'])) {
-      send_binary_content($this->get_conf_data(), CONFIG_FILE, "text/plain");
-    }
-
-    $err_msg = "";
-
-    if ($exists && $this->is_world_readable(CONFIG_DIR."/".CONFIG_FILE)) {
-      $err_msg = _("Your configuration file is currently world readable. Please update the file permissions!");
-    } elseif (!$exists) {
-      $err_msg = _("The configuration is currently not readable or it does not exists.");
+      send_binary_content($this->get_conf_data(), CONFIG_FILE, 'text/plain');
     }
-
-    $smarty = get_smarty();
-    $smarty->assign("err_msg",  $err_msg);
-    $smarty->assign("msg2",     sprintf(_("After downloading and placing the file under %s, please make sure that the user the webserver is running with is able to read %s, while other users shouldn't."), CONFIG_DIR, CONFIG_FILE));
-
-    //~ Changer ça pour du sp.
-
-    return $smarty->fetch("$BASE_DIR/setup/setup_finish.tpl");
   }
 
   /* check if given file is world readable */
@@ -121,5 +128,4 @@ class Step_Finish extends setup_step
     return (decbin($p & 4) == TRUE);
   }
 }
-
 ?>
diff --git a/setup/class_setupStep_Migrate.inc b/setup/class_setupStep_Migrate.inc
index 5a613a9fe..a5e10f76d 100644
--- a/setup/class_setupStep_Migrate.inc
+++ b/setup/class_setupStep_Migrate.inc
@@ -142,7 +142,6 @@ class StepMigrateCheck
 
   public function save_object()
   {
-    $this->is_completed = TRUE;
     if (isset($_POST[$this->name.'_create'])) {
       $fnc = $this->fnc.'_create';
       $this->step->$fnc($this);
@@ -309,6 +308,7 @@ class Step_Migrate extends setupStep
 
   function save_object()
   {
+    $this->is_completed = TRUE;
     parent::save_object();
     foreach ($this->checks as &$check) {
       $check->save_object();
diff --git a/setup/setup_finish.tpl b/setup/setup_finish.tpl
index b9fcaa5a8..cd1c04c91 100644
--- a/setup/setup_finish.tpl
+++ b/setup/setup_finish.tpl
@@ -6,7 +6,7 @@
     {$msg2}
   </p>
   <p>
-    {t}Run {/t}<a style="color:black ; font-weight:bold ">fusiondirectory-setup --check-config</a>{t} to put the correct right on fusiondirectory.conf{/t}
+    {t escape=no 1="<strong>fusiondirectory-setup --check-config</strong>"}Run %1 to put the correct right on fusiondirectory.conf{/t}
   </p>
   <p>
     <input type="submit" name="getconf" value="{t}Download configuration{/t}"/>
@@ -15,8 +15,6 @@
       <hr/>
       <br/>
       {t}Status: {/t}
-      <a style="color:red ; font-weight:bold ">{$err_msg}</a>
+      <strong>{$err_msg}</strong>
     {/if}
-
 </div>
-<input type="hidden" value="1" name="step8_posted"/>
diff --git a/setup/setup_migrate.tpl b/setup/setup_migrate.tpl
index 7846ea5f6..fe194fdf5 100644
--- a/setup/setup_migrate.tpl
+++ b/setup/setup_migrate.tpl
@@ -4,25 +4,24 @@
   </span>
   <div>
     {foreach from=$attributes item=checks}
-
       <p>{t}During the LDAP inspection, we're going to check for several common pitfalls that may occur when migration to FusionDirectory base LDAP administration. You may want to fix the problems below, in order to provide smooth services.{/t}
       </p>
 
       {foreach from=$checks item=check key=key}
-        <div style='width:98%; padding:4px; background-color:{cycle values="#F0F0F0, #FFF"}'>
+        <div style="width:98%; padding:4px; background-color:{cycle values="#F0F0F0, #FFF"}">
           {if $check->error}
             <!-- Add ability to display info popup -->
-            <div class='step2_entry_container_info'>
+            <div class="step2_entry_container_info">
           {else}
             <!-- Normal entry everything is fine -->
-            <div class='step2_entry_container'>
+            <div class="step2_entry_container">
           {/if}
-          <div class='step2_entry_name'><b>{$check->title}</b></div>
-          <div class='step2_entry_status'>
+          <div class="step2_entry_name"><b>{$check->title}</b></div>
+          <div class="step2_entry_status">
             {if $check->status}
-              <div class='step2_successful'>{$check->msg}</div>
+              <div class="step2_successful">{$check->msg}</div>
             {else}
-              <div class='step2_failed'>{$check->msg}</div>
+              <div class="step2_failed">{$check->msg}</div>
             {/if}
           </div>
             {if $check->error}
@@ -31,9 +30,8 @@
           </div>
         </div>
       {/foreach}
-    <br/>
-    <input type='submit' name='reload' value='{t}Check again{/t}'/>
-
     {/foreach}
+    <br/>
+    <input type="submit" name="reload" value="{t}Check again{/t}"/>
   </div>
 </div>
-- 
GitLab