From 14922c1f0ce5d252cbb9d0b801f186ab95782a94 Mon Sep 17 00:00:00 2001
From: Laurent Giovannoni <laurent.giovannoni@maarch.org>
Date: Wed, 16 Mar 2011 08:20:08 +0000
Subject: [PATCH] evol : code duplication

---
 core/trunk/core/admin_tools.inc               | 104 ++++++++++++++++++
 core/trunk/core/class/class_resource.php      |   2 +-
 .../trunk/core/class/docservers_controler.php |   2 +-
 ...cserversTools.inc => docservers_tools.inc} |   0
 4 files changed, 106 insertions(+), 2 deletions(-)
 create mode 100644 core/trunk/core/admin_tools.inc
 rename core/trunk/core/{DocserversTools.inc => docservers_tools.inc} (100%)

diff --git a/core/trunk/core/admin_tools.inc b/core/trunk/core/admin_tools.inc
new file mode 100644
index 00000000000..7ddd8a6900a
--- /dev/null
+++ b/core/trunk/core/admin_tools.inc
@@ -0,0 +1,104 @@
+<?php
+
+/*
+*   Copyright 2008-2011 Maarch
+*
+*   This file is part of Maarch Framework.
+*
+*   Maarch Framework is free software: you can redistribute it and/or modify
+*   it under the terms of the GNU General Public License as published by
+*   the Free Software Foundation, either version 3 of the License, or
+*   (at your option) any later version.
+*
+*   Maarch Framework is distributed in the hope that it will be useful,
+*   but WITHOUT ANY WARRANTY; without even the implied warranty of
+*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+*   GNU General Public License for more details.
+*
+*   You should have received a copy of the GNU General Public License
+*   along with Maarch Framework. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+/**
+* @brief API to manage admin 
+*
+* @file
+* @author Laurent Giovannoni
+* @date $date$
+* @version $Revision$
+* @ingroup core
+*/
+
+
+/**
+ * Format given item with given values, according with HTML formating.
+ * NOTE: given item needs to be an array with at least 2 keys: 
+ * 'column' and 'value'.
+ * NOTE: given item is modified consequently.  
+ * @param $item
+ * @param $label
+ * @param $size
+ * @param $label_align
+ * @param $align
+ * @param $valign
+ * @param $show
+ */
+function At_formatItem(
+    &$item, $label , $size , $labelAlign, $align, $valign, $show
+) {
+    $func = new functions();
+    $item['value'] = $func->show_string($item['value']);    
+    $item[$item['column']] = $item['value'];
+    $item["label"] = $label;
+    $item["size"] = $size;
+    $item["label_align"] = $labelAlign;
+    $item["align"] = $align;
+    $item["valign"] = $valign;
+    $item["show"] = $show;
+    $item["order"] = $item['column'];    
+}
+
+/**
+ * Put given object in session, according with given type
+ * NOTE: given object needs to be at least hashable
+ * @param string $type
+ * @param hashable $hashable
+ */
+function At_putInSession($type, $hashable)
+{
+    $func = new functions();
+    foreach ($hashable as $key => $value) {
+        $_SESSION['m_admin'][$type][$key] = $func->show_string($value);
+    }
+}
+
+/**
+ * Show the admin list of an Ajax request 
+ * @param object $db database request object
+ * @param string $whatRequest request string
+ */
+function At_showAjaxList($db, $whatRequest)
+{
+    $listArray = array();
+    while ($line = $db->fetch_object()) {
+        array_push($listArray, $line->tag);
+    }
+    echo "<ul>\n";
+    $authViewList = 0;
+    $flagAuthView = false;
+    foreach ($listArray as $what) {
+        if (isset($authViewList) && $authViewList >= 10) {
+            $flagAuthView = true;
+        }
+        if (stripos($what, $whatRequest) === 0) {
+            echo "<li>".$what."</li>\n";
+            if ($flagAuthView) {
+                echo "<li>...</li>\n";
+                break;
+            }
+            $authViewList++;
+        }
+    }
+    echo "</ul>";
+}
+
diff --git a/core/trunk/core/class/class_resource.php b/core/trunk/core/class/class_resource.php
index d69c82c164e..d00c87661c2 100644
--- a/core/trunk/core/class/class_resource.php
+++ b/core/trunk/core/class/class_resource.php
@@ -138,7 +138,7 @@
 		$filetmp .= $filename;
 		require_once("core" . DIRECTORY_SEPARATOR . "class" . DIRECTORY_SEPARATOR . "docservers_controler.php");
 		require_once("core" . DIRECTORY_SEPARATOR . "class" . DIRECTORY_SEPARATOR . "docserver_types_controler.php");
-		require_once("core" . DIRECTORY_SEPARATOR . "DocserversTools.inc");
+		require_once("core" . DIRECTORY_SEPARATOR . "docservers_tools.inc");
 		$docserverControler = new docservers_controler();
 		$docserverTypeControler = new docserver_types_controler();
 		$docserver = $docserverControler->get($docserver_id);
diff --git a/core/trunk/core/class/docservers_controler.php b/core/trunk/core/class/docservers_controler.php
index 75fb485e20c..55df19f76bf 100644
--- a/core/trunk/core/class/docservers_controler.php
+++ b/core/trunk/core/class/docservers_controler.php
@@ -37,7 +37,7 @@ $_ENV['DEBUG'] = false;
 //Loads the required class
 try {
     require_once ('core/class/docservers.php');
-    require_once ('core/DocserversTools.inc');
+    require_once ('core/docservers_tools.inc');
     require_once ('core/core_tables.php');
     require_once ('core/class/ObjectControlerAbstract.php');
     require_once ('core/class/ObjectControlerIF.php');
diff --git a/core/trunk/core/DocserversTools.inc b/core/trunk/core/docservers_tools.inc
similarity index 100%
rename from core/trunk/core/DocserversTools.inc
rename to core/trunk/core/docservers_tools.inc
-- 
GitLab