]> _ Git - cubeextranet.git/commitdiff
wip #3270 @6
authorvincent@cubedesigners.com <vincent@cubedesigners.com@f5622870-0f3c-0410-866d-9cb505b7a8ef>
Tue, 17 Dec 2019 12:24:55 +0000 (12:24 +0000)
committervincent@cubedesigners.com <vincent@cubedesigners.com@f5622870-0f3c-0410-866d-9cb505b7a8ef>
Tue, 17 Dec 2019 12:24:55 +0000 (12:24 +0000)
inc/ws/Controlleur/class.ws.ajax.php
inc/ws/Controlleur/class.ws.url.php
inc/ws/Metier/class.ws.parametres.php
inc/ws/Util/class.ws.util.php

index 15e5d2709b34555195b7eb74a0358ffd00f78f8b..33442d1ea48c4690e8312816dc380c451aeaca0a 100644 (file)
@@ -1312,4 +1312,36 @@ class wsAjax extends cubeAjax
 
         self::cleanCachesCollection($id);
     }
+
+    public static function importFluidbookSettings($args, &$x)
+    {
+        global $core;
+        $dao = new wsDAOBook($core->con);
+
+        new PHPExcel();
+
+        $reader = new PHPExcel_Reader_Excel2007();
+        $xls = $reader->load($_FILES['file']['tmp_name']);
+
+        $ignore = wsUrl::getReadonlySettings();
+
+        $sheet = $xls->getActiveSheet()->toArray();
+        $nlines = count($sheet);
+        for ($i = 1; $i < $nlines; $i++) {
+            $line = $sheet[$i];
+            $id = (int)$line[0];
+            if (!$id) {
+                continue;
+            }
+            $settings = [];
+            foreach ($line as $k => $v) {
+                $col = $sheet[0][$k];
+                if (in_array($col, $ignore, true)) {
+                    continue;
+                }
+                $settings[$col] = $v;
+            }
+            $dao->setSettings($id, $settings);
+        }
+    }
 }
\ No newline at end of file
index 57ff353705d4032aecc0a6ecbc2cb087510024cc..d60aded3baa3e52a8a6f2b317853fe82f06501ba 100644 (file)
@@ -2207,6 +2207,16 @@ html.tall{height:150%}' . "\n";
         header('Location: https://www.orpi.com/');
     }
 
+    public static function getAdditionalSettingsMap(): array
+    {
+        return ['book_id' => 'book_id', 'lang' => 'lang', 'theme' => 'theme', 'status' => 'status', 'proprietaire_id' => 'owner', 'date' => 'date', 'changedate' => 'changedate', 'hosting' => 'hosting', 'exportdatas' => 'exportdata'];
+    }
+
+    public static function getReadonlySettings()
+    {
+        return ['book_id', 'date', 'changedate', 'hosting', 'exportdatas'];
+    }
+
     public static function exportPublicationSettings($args)
     {
         global $core;
@@ -2221,23 +2231,15 @@ html.tall{height:150%}' . "\n";
         $xls = new PHPExcel();
         $sheet = $xls->getActiveSheet();
         $sheet->freezePane('B2');
-        $standardSettings = ['book_id' => 'book_id', 'lang' => 'lang', 'theme' => 'theme', 'status' => 'status', 'proprietaire_id' => 'owner', 'date' => 'date', 'changedate' => 'changedate', 'hosting' => 'hosting', 'exportdatas' => 'exportdata'];
+        $standardSettings = self::getAdditionalSettingsMap();
+        $readonlyList = self::getReadonlySettings();
         $j = 0;
         foreach ($standardSettings as $column => $label) {
-            $readonly = false;
-            if ($label === 'exportdata') {
-                $readonly = true;
-            } else {
+            if ($label !== 'exportdata') {
                 $sheet->getColumnDimensionByColumn($j)->setAutoSize(true);
             }
-            if ($label === 'hosting') {
-                $readonly = true;
-            }
 
-            if (strpos($column, 'date') !== false) {
-                $readonly = true;
-            }
-            if ($readonly) {
+            if (in_array($column, $readonlyList, true)) {
                 self::_readonlyStyle($sheet->getStyle(PHPExcel_Cell::stringFromColumnIndex($j)));
             }
             $sheet->setCellValueByColumnAndRow($j, 1, $label);
index 416703605514c62f3b30bd01ebd6e7ae95c1a0c5..f4ffd94e532480618f06d766f33851c2cdbe6dab 100644 (file)
 <?php\r
 \r
-class wsParametres extends cubeMetier implements Iterator {\r
-\r
-       protected $datas;\r
-       protected $fields;\r
-       protected $forms;\r
-       protected $parent;\r
-\r
-       // Magic functions\r
-       public function __construct($parent) {\r
-               $this->parent = $parent;\r
-               $this->initFields();\r
-               $this->datas = array();\r
-               $this->setDefaultValues();\r
-       }\r
-\r
-       public function isEmpty() {\r
-               return count($this->datas) == 0;\r
-       }\r
-\r
-       public function setParent($parent) {\r
-               $this->parent = $parent;\r
-               $this->initFields();\r
-       }\r
-\r
-       public function __set($varname, $value) {\r
-               if (empty($varname)) {\r
-                       return;\r
-               }\r
-               $this->set($varname, $value);\r
-       }\r
-\r
-       public function __unset($varname) {\r
-               $this->set($varname, null);\r
-       }\r
-\r
-       public function __get($varname) {\r
-               return $this->get($varname);\r
-       }\r
-\r
-       public function __isset($varname) {\r
-               return $this->_isset($varname);\r
-       }\r
-\r
-       public function __sleep() {\r
-               return array('datas');\r
-       }\r
-\r
-       public function __wakeup() {\r
-               $this->initFields();\r
-       }\r
-\r
-       // Iterator functions\r
-       public function rewind() {\r
-               reset($this->fields);\r
-       }\r
-\r
-       public function current() {\r
-               return $this->get($this->key());\r
-       }\r
-\r
-       public function key() {\r
-               return key($this->fields);\r
-       }\r
-\r
-       public function next() {\r
-               return next($this->fields);\r
-       }\r
-\r
-       public function valid() {\r
-               return $this->_isset($this->key());\r
-       }\r
-\r
-       protected function initFields() {\r
-               $this->fields = array();\r
-               $this->forms = array();\r
-       }\r
-\r
-       protected function setDefaultValues() {\r
-               foreach ($this->fields as $k => $f) {\r
-                       if (isset($f["default"])) {\r
-                               $this->set($k, $f['default']);\r
-                       }\r
-               }\r
-       }\r
-\r
-       protected function set($varname, $value) {\r
-               if (!$this->_isset($varname)) {\r
-                       throw new Exception('You are setting an attribute (' . get_class($this) . '::' . $varname . ') which not exists');\r
-               }\r
-\r
-               if (is_null($value)) {\r
-                       $this->datas[$varname] = null;\r
-                       return;\r
-               }\r
-\r
-               switch ($this->fields[$varname]['type']) {\r
-                       case 'integer':\r
-                               if (!is_int($value)) {\r
-                                       $value = intval($value);\r
-                               }\r
-                               break;\r
-                       case 'float':\r
-                               if (!is_float($value)) {\r
-                                       $value = floatval($value);\r
-                               }\r
-                               break;\r
-                       case 'boolean':\r
-                               if (!is_bool($value)) {\r
-                                       $value = ($value == '' || $value == '0' || $value == 'false') ? false : true;\r
-                               }\r
-                               break;\r
-                       case 'color':\r
-                       case 'couleur':\r
-                               $value = cubeMath::fill(ltrim($value, '#'), 6);\r
-                               break;\r
-                       case 'couleurAlpha':\r
-                               $value = cubeMath::fill(ltrim($value, '#'), 6);\r
-                               $value = cubeMath::fill($value, 8, 'f');\r
-                               break;\r
-                       case 'date':\r
-                               if (!is_int($value)) {\r
-                                       $value = intval($value);\r
-                               }\r
-                               break;\r
-                       case 'file':\r
-                               $e = explode('/', $value);\r
-                               $value = array_pop($e);\r
-                               break;\r
-                       default:\r
-                               $value = (string)$value;\r
-                               break;\r
-               } // switch\r
-               $this->datas[$varname] = $value;\r
-       }\r
-\r
-       protected function _isset($varname) {\r
-               return isset($this->fields[$varname]) && isset($this->fields[$varname]['default']);\r
-       }\r
-\r
-       protected function get($varname) {\r
-               if (is_null($varname)) {\r
-                       return false;\r
-               }\r
-               if (!$this->_isset($varname)) {\r
-                       throw new Exception('You are getting an attribute (' . get_class($this) . '::' . $varname . ') which not exists');\r
-               }\r
-               if (!isset($this->datas[$varname]) || is_null($this->datas[$varname])) {\r
-                       return $this->getDefault($varname);\r
-               }\r
-               return $this->datas[$varname];\r
-       }\r
-\r
-       protected function getDefault($varname) {\r
-               if (substr($this->fields[$varname]['default'], 0, 1) == '$') {\r
-                       return $this->get(substr($this->fields[$varname]['default'], 1));\r
-               } else {\r
-                       return $this->fields[$varname]['default'];\r
-               }\r
-       }\r
-\r
-       public function getForm($name,$ignoreMeta=false) {\r
-               $f = $this->forms[$name];\r
-               $f['fields'] = array();\r
-               foreach ($f['fieldsnames'] as $n) {\r
-                       if ($n == '|') {\r
-                           if($ignoreMeta){\r
-                               continue;\r
+class wsParametres extends cubeMetier implements Iterator\r
+{\r
+\r
+    protected $datas;\r
+    protected $fields;\r
+    protected $forms;\r
+    protected $parent;\r
+\r
+    // Magic functions\r
+    public function __construct($parent)\r
+    {\r
+        $this->parent = $parent;\r
+        $this->initFields();\r
+        $this->datas = array();\r
+        $this->setDefaultValues();\r
+    }\r
+\r
+    public function isEmpty()\r
+    {\r
+        return count($this->datas) == 0;\r
+    }\r
+\r
+    public function setParent($parent)\r
+    {\r
+        $this->parent = $parent;\r
+        $this->initFields();\r
+    }\r
+\r
+    public function __set($varname, $value)\r
+    {\r
+        if (empty($varname)) {\r
+            return;\r
+        }\r
+        $this->set($varname, $value);\r
+    }\r
+\r
+    public function __unset($varname)\r
+    {\r
+        $this->set($varname, null);\r
+    }\r
+\r
+    public function __get($varname)\r
+    {\r
+        return $this->get($varname);\r
+    }\r
+\r
+    public function __isset($varname)\r
+    {\r
+        return $this->_isset($varname);\r
+    }\r
+\r
+    public function __sleep()\r
+    {\r
+        return array('datas');\r
+    }\r
+\r
+    public function __wakeup()\r
+    {\r
+        $this->initFields();\r
+    }\r
+\r
+    // Iterator functions\r
+    public function rewind()\r
+    {\r
+        reset($this->fields);\r
+    }\r
+\r
+    public function current()\r
+    {\r
+        return $this->get($this->key());\r
+    }\r
+\r
+    public function key()\r
+    {\r
+        return key($this->fields);\r
+    }\r
+\r
+    public function next()\r
+    {\r
+        return next($this->fields);\r
+    }\r
+\r
+    public function valid()\r
+    {\r
+        return $this->_isset($this->key());\r
+    }\r
+\r
+    protected function initFields()\r
+    {\r
+        $this->fields = array();\r
+        $this->forms = array();\r
+    }\r
+\r
+    protected function setDefaultValues()\r
+    {\r
+        foreach ($this->fields as $k => $f) {\r
+            if (isset($f["default"])) {\r
+                $this->set($k, $f['default']);\r
+            }\r
+        }\r
+    }\r
+\r
+    protected function set($varname, $value)\r
+    {\r
+        if (!$this->_isset($varname)) {\r
+            throw new Exception('You are setting an attribute (' . get_class($this) . '::' . $varname . ') which not exists');\r
+        }\r
+\r
+        if (is_null($value)) {\r
+            $this->datas[$varname] = null;\r
+            return;\r
+        }\r
+\r
+        switch ($this->fields[$varname]['type']) {\r
+            case 'integer':\r
+                if (!is_int($value)) {\r
+                    $value = intval($value);\r
                 }\r
-                               $f['fields'][] = '|';\r
-                       } else {\r
-                               $f['fields'][$n] = $this->fields[$n];\r
-                               $f['fields'][$n]['value'] = $this->get($n);\r
-                       }\r
-               }\r
-               return $f;\r
-       }\r
-\r
-       public function getForms() {\r
-               return array_keys($this->forms);\r
-       }\r
-\r
-       public function fromRecord($r) {\r
-               $c = array_flip($r->columns());\r
-               foreach ($this->fields as $n => $f) {\r
-                       if (isset($c[$n]) && !is_null($r->$n)) {\r
-                               $this->set($n, $r->$n);\r
-                       }\r
-               }\r
-       }\r
-\r
-       public function fromXML($xml) {\r
-               foreach ($this->fields as $n => $f) {\r
-                       $xp = $xml->$n;\r
-                       if (!$xp || !count($xp)) {\r
-                               continue;\r
-                       }\r
-                       foreach ($xp as $x) {\r
-                               $this->set($n, $x);\r
-                       }\r
-               }\r
-       }\r
-\r
-       public function toStandardObject() {\r
-               $res = new stdClass();\r
-               foreach ($this as $k => $v) {\r
-                       $res->$k = $v;\r
-               }\r
-               return $res;\r
-       }\r
-\r
-       public function getHelp() {\r
-               $rubriques = array();\r
-               foreach ($this->forms as $name => $form) {\r
-                       $rub = array();\r
-                       foreach ($form['fieldsnames'] as $f) {\r
-                               if ($f == '|') {\r
-                                       $rub[] = '|';\r
-                               } else {\r
-\r
-                                       $d = self::formatValueForHelp($this->getDefault($f));\r
-                                       $v = self::formatValueForHelp($this->get($f));\r
-                                       if ($d != $v) {\r
-                                               $v = '<strong>' . $v . '</strong>';\r
-                                       }\r
-\r
-\r
-                                       $field = $this->fields[$f];\r
-                                       $t = array();\r
-                                       $t[] = $f;\r
-                                       $t[] = $field['type'];\r
-                                       $t[] = $field['label'];\r
-                                       $t[] = $d;\r
-                                       $t[] = $v;\r
-                                       $rub[$f] = $t;\r
-                               }\r
-                       }\r
-                       $rubriques[$form['label']] = $rub;\r
-               }\r
-               return $rubriques;\r
-       }\r
-\r
-       public static function formatValueForHelp($v) {\r
-               if (is_bool($v)) {\r
-                       $v = ($v) ? 'true' : 'false';\r
-               }\r
-               return $v;\r
-       }\r
+                break;\r
+            case 'float':\r
+                if (!is_float($value)) {\r
+                    $value = floatval($value);\r
+                }\r
+                break;\r
+            case 'boolean':\r
+                if ($value === 'TRUE') {\r
+                    $value = true;\r
+                }\r
+                if ($value === 'FALSE') {\r
+                    return false;\r
+                }\r
+                if (!is_bool($value)) {\r
+                    $value = !($value == '' || $value == '0' || $value === 'false');\r
+                }\r
+                $value = (bool)$value;\r
+                break;\r
+            case 'color':\r
+            case 'couleur':\r
+                $value = cubeMath::fill(ltrim($value, '#'), 6);\r
+                break;\r
+            case 'couleurAlpha':\r
+                $value = cubeMath::fill(ltrim($value, '#'), 6);\r
+                $value = cubeMath::fill($value, 8, 'f');\r
+                break;\r
+            case 'date':\r
+                if (!is_int($value)) {\r
+                    $value = intval($value);\r
+                }\r
+                break;\r
+            case 'file':\r
+                $e = explode('/', $value);\r
+                $value = array_pop($e);\r
+                break;\r
+            default:\r
+                $value = (string)$value;\r
+                break;\r
+        } // switch\r
+        $this->datas[$varname] = $value;\r
+    }\r
+\r
+    protected function _isset($varname)\r
+    {\r
+        return isset($this->fields[$varname]) && isset($this->fields[$varname]['default']);\r
+    }\r
+\r
+    protected function get($varname)\r
+    {\r
+        if (is_null($varname)) {\r
+            return false;\r
+        }\r
+        if (!$this->_isset($varname)) {\r
+            throw new Exception('You are getting an attribute (' . get_class($this) . '::' . $varname . ') which not exists');\r
+        }\r
+        if (!isset($this->datas[$varname]) || is_null($this->datas[$varname])) {\r
+            return $this->getDefault($varname);\r
+        }\r
+        return $this->datas[$varname];\r
+    }\r
+\r
+    protected function getDefault($varname)\r
+    {\r
+        if (substr($this->fields[$varname]['default'], 0, 1) == '$') {\r
+            return $this->get(substr($this->fields[$varname]['default'], 1));\r
+        } else {\r
+            return $this->fields[$varname]['default'];\r
+        }\r
+    }\r
+\r
+    public function getForm($name, $ignoreMeta = false)\r
+    {\r
+        $f = $this->forms[$name];\r
+        $f['fields'] = array();\r
+        foreach ($f['fieldsnames'] as $n) {\r
+            if ($n == '|') {\r
+                if ($ignoreMeta) {\r
+                    continue;\r
+                }\r
+                $f['fields'][] = '|';\r
+            } else {\r
+                $f['fields'][$n] = $this->fields[$n];\r
+                $f['fields'][$n]['value'] = $this->get($n);\r
+            }\r
+        }\r
+        return $f;\r
+    }\r
+\r
+    public function getForms()\r
+    {\r
+        return array_keys($this->forms);\r
+    }\r
+\r
+    public function fromRecord($r)\r
+    {\r
+        $c = array_flip($r->columns());\r
+        foreach ($this->fields as $n => $f) {\r
+            if (isset($c[$n]) && !is_null($r->$n)) {\r
+                $this->set($n, $r->$n);\r
+            }\r
+        }\r
+    }\r
+\r
+    public function fromXML($xml)\r
+    {\r
+        foreach ($this->fields as $n => $f) {\r
+            $xp = $xml->$n;\r
+            if (!$xp || !count($xp)) {\r
+                continue;\r
+            }\r
+            foreach ($xp as $x) {\r
+                $this->set($n, $x);\r
+            }\r
+        }\r
+    }\r
+\r
+    public function toStandardObject()\r
+    {\r
+        $res = new stdClass();\r
+        foreach ($this as $k => $v) {\r
+            $res->$k = $v;\r
+        }\r
+        return $res;\r
+    }\r
+\r
+    public function toArray()\r
+    {\r
+        $res = [];\r
+        foreach ($this as $k => $v) {\r
+            $res[$k]=$v;\r
+        }\r
+        return $res;\r
+    }\r
+\r
+    public function getHelp()\r
+    {\r
+        $rubriques = array();\r
+        foreach ($this->forms as $name => $form) {\r
+            $rub = array();\r
+            foreach ($form['fieldsnames'] as $f) {\r
+                if ($f == '|') {\r
+                    $rub[] = '|';\r
+                } else {\r
+\r
+                    $d = self::formatValueForHelp($this->getDefault($f));\r
+                    $v = self::formatValueForHelp($this->get($f));\r
+                    if ($d != $v) {\r
+                        $v = '<strong>' . $v . '</strong>';\r
+                    }\r
+\r
+\r
+                    $field = $this->fields[$f];\r
+                    $t = array();\r
+                    $t[] = $f;\r
+                    $t[] = $field['type'];\r
+                    $t[] = $field['label'];\r
+                    $t[] = $d;\r
+                    $t[] = $v;\r
+                    $rub[$f] = $t;\r
+                }\r
+            }\r
+            $rubriques[$form['label']] = $rub;\r
+        }\r
+        return $rubriques;\r
+    }\r
+\r
+    public static function formatValueForHelp($v)\r
+    {\r
+        if (is_bool($v)) {\r
+            $v = ($v) ? 'true' : 'false';\r
+        }\r
+        return $v;\r
+    }\r
 \r
 }
\ No newline at end of file
index 4510ce25ec2f3651090840a7315d852a0f61ded0..073fbf14501b287bf4dda7cab8a6b9f72b94255d 100644 (file)
@@ -103,7 +103,8 @@ class wsUtil
             }\r
             $colslabels[$j] = $collabel;\r
         }\r
-        for ($i = 1; $i < count($s); $i++) {\r
+        $cs = count($s);\r
+        for ($i = 1; $i < $cs; $i++) {\r
             $r = [];\r
             foreach ($colslabels as $j => $collabel) {\r
                 $r[$collabel] = $s[$i][$j];\r