<?php\r
\r
-class wsDAOTheme extends commonDAO {\r
-\r
- protected function singleton($r) {\r
- $theme = new wsTheme();\r
- $theme->theme_id = $r->theme_id;\r
- $theme->nom = $r->nom;\r
- $theme->date = $r->date;\r
- $theme->proprietaire = $r->proprietaire;\r
- if ($r->exists('nbBooks')) {\r
- $theme->nbBooks = $r->nbBooks;\r
- }\r
- if ($r->exists('proprietaire_nom')) {\r
- $theme->proprietaire_nom = $r->proprietaire_nom;\r
- }\r
- $theme->signature = $r->signature;\r
- $theme->icones = $r->icones;\r
- $p = unserialize($r->parametres);\r
- if (!$p) {\r
- $p = new wsThemeParametres($theme);\r
- } else {\r
- $p->setParent($theme);\r
- }\r
- $theme->parametres = $p;\r
-\r
- return $theme;\r
- }\r
-\r
- public function selectById($theme_id, $table = 'themes_vue') {\r
- $r = $this->con->select('SELECT * FROM ' . $table . ' WHERE theme_id=\'' . $this->con->escape($theme_id) . '\' LIMIT 1');\r
- return $this->singleton($r);\r
- }\r
-\r
- public function getThemeOfBook($book_id, $basic = false) {\r
- if ($basic) {\r
- $table = 'themes';\r
- } else {\r
- $table = 'themes_vue';\r
- }\r
- $r = $this->con->select('SELECT * FROM ' . $table . ' WHERE theme_id IN (SELECT theme FROM books WHERE book_id=\'' . $this->con->escape($book_id) . '\') LIMIT 1');\r
- return $this->singleton($r);\r
- }\r
-\r
- public function getAllThemes($user, $order = '', $demos = null) {\r
- if (wsDroits::admin(false)) {\r
- $sql = 'SELECT * FROM themes_vue';\r
- } else {\r
- $or = '';\r
- if (wsDroits::revendeur() && !is_null($demos)) {\r
- $or = ' OR theme_id IN(' . implode(',', $demos) . ')';\r
- }\r
- $sql = 'SELECT * FROM themes_vue WHERE theme_id IN (SELECT theme FROM books WHERE proprietaire IN(' . $user->ws_rights . ') ' . $or . ')';\r
- }\r
- $r = $this->con->select($sql . ' ' . $order);\r
- return $this->factory($r);\r
- }\r
-\r
- public function sauve($data) {\r
- $parent = $this->selectById($data['theme_id']);\r
- $c = $this->con->openCursor('themes');\r
- $c->date = TIME;\r
- $p = new wsThemeParametres($parent);\r
- foreach ($data as $k => $v) {\r
- if (!isset($p->$k)) {\r
- continue;\r
- }\r
- $p->$k = $v;\r
- }\r
- $c->parametres = serialize($p);\r
- $c->update('WHERE theme_id=\'' . $this->con->escape($data['theme_id']) . '\'');\r
- if (file_exists(WS_THEMES . '/' . $data['theme_id'] . '.jpg')) {\r
- unlink(WS_THEMES . '/' . $data['theme_id'] . '.jpg');\r
- }\r
- }\r
-\r
- protected function getNextId() {\r
- $r = $this->con->select('SELECT MAX(theme_id) AS theme_id FROM themes');\r
- if ($r->theme_id < 1000) {\r
- return 1000;\r
- }\r
- return $r->theme_id + 1;\r
- }\r
-\r
- public function delete($theme_id, $onlyFiles = false) {\r
- if (is_null($theme_id) || $theme_id == '') {\r
- return;\r
- }\r
- if (!$onlyFiles) {\r
- $this->con->execute('DELETE FROM themes WHERE theme_id=\'' . $this->con->escape($theme_id) . '\'');\r
- }\r
- $fref = WS_THEMES . '/' . $theme_id;\r
- if (file_exists($fref)) {\r
- files::deltree($fref);\r
- }\r
- if (file_exists($fref . '.jpg')) {\r
- unlink($fref . '.jpg');\r
- }\r
- }\r
-\r
- public function rename($theme_id, $newname) {\r
- $c = $this->con->openCursor('themes');\r
- $c->nom = $newname;\r
- $c->update('WHERE theme_id=\'' . $this->con->escape($theme_id) . '\'');\r
- }\r
-\r
- public function duplicate($theme_id, $proprietaire) {\r
- if (is_null($theme_id) || $theme_id == '') {\r
- return;\r
- }\r
- $theme = $this->selectById($theme_id);\r
- // Copie des données\r
- $c = $this->con->openCursor('themes');\r
- $c->theme_id = $this->getNextId();\r
- $c->nom = $theme->nom . ' (copy)';\r
- $c->parametres = serialize($theme->parametres);\r
- $c->signature = $theme->signature;\r
- $c->icones = $theme->icones;\r
- $c->proprietaire = $proprietaire;\r
- $c->date = TIME;\r
- $c->insert();\r
-\r
- $this->delete($c->theme_id, true);\r
- // Copie des fichiers\r
- $from = WS_THEMES . '/' . $theme_id;\r
- $to = WS_THEMES . '/' . $c->theme_id;\r
- $dr = opendir($from);\r
- if (!file_exists($to)) {\r
- mkdir($to, 0777, true);\r
- } else {\r
- files::deltree($to);\r
- mkdir($to, 0777, true);\r
- } //.\r
- while ($file = readdir($dr)) {\r
- if ($file == '.' || $file == '..') {\r
- continue;\r
- }\r
- copy($from . '/' . $file, $to . '/' . $file);\r
- }\r
- if (file_exists($from . '.jpg')) {\r
- copy($from . '.jpg', $to . '.jpg');\r
- }\r
-\r
- return $this->selectById($c->theme_id);\r
- }\r
-\r
-}\r
-\r
-?>
\ No newline at end of file
+class wsDAOTheme extends commonDAO\r
+{\r
+\r
+ protected function singleton($r)\r
+ {\r
+ $theme = new wsTheme();\r
+ $theme->theme_id = $r->theme_id;\r
+ $theme->nom = $r->nom;\r
+ $theme->date = $r->date;\r
+ $theme->proprietaire = $r->proprietaire;\r
+ if ($r->exists('nbBooks')) {\r
+ $theme->nbBooks = $r->nbBooks;\r
+ }\r
+ if ($r->exists('proprietaire_nom')) {\r
+ $theme->proprietaire_nom = $r->proprietaire_nom;\r
+ }\r
+ $theme->signature = $r->signature;\r
+ $theme->icones = $r->icones;\r
+ $p = unserialize($r->parametres);\r
+ if (!$p) {\r
+ $p = new wsThemeParametres($theme);\r
+ } else {\r
+ $p->setParent($theme);\r
+ }\r
+ $theme->parametres = $p;\r
+\r
+ return $theme;\r
+ }\r
+\r
+ public function selectById($theme_id, $table = 'themes_vue')\r
+ {\r
+ $r = $this->con->select('SELECT * FROM ' . $table . ' WHERE theme_id=\'' . $this->con->escape($theme_id) . '\' LIMIT 1');\r
+ return $this->singleton($r);\r
+ }\r
+\r
+ public function getThemeOfBook($book_id, $basic = false)\r
+ {\r
+ if ($basic) {\r
+ $table = 'themes';\r
+ } else {\r
+ $table = 'themes_vue';\r
+ }\r
+ $r = $this->con->select('SELECT * FROM ' . $table . ' WHERE theme_id IN (SELECT theme FROM books WHERE book_id=\'' . $this->con->escape($book_id) . '\') LIMIT 1');\r
+ return $this->singleton($r);\r
+ }\r
+\r
+ public function getAllThemes($user, $order = '', $demos = null)\r
+ {\r
+ if (wsDroits::admin(false)) {\r
+ $sql = 'SELECT * FROM themes_vue';\r
+ } else {\r
+ $or = '';\r
+ if (wsDroits::revendeur() && !is_null($demos)) {\r
+ $or = ' OR theme_id IN(' . implode(',', $demos) . ')';\r
+ }\r
+ $sql = 'SELECT * FROM themes_vue WHERE theme_id IN (SELECT theme FROM books WHERE proprietaire IN(' . $user->ws_rights . ') ' . $or . ')';\r
+ }\r
+ $r = $this->con->select($sql . ' ' . $order);\r
+ return $this->factory($r);\r
+ }\r
+\r
+ public function sauve($data)\r
+ {\r
+ $parent = $this->selectById($data['theme_id']);\r
+ $c = $this->con->openCursor('themes');\r
+ $c->date = TIME;\r
+ $p = new wsThemeParametres($parent);\r
+ foreach ($data as $k => $v) {\r
+ if (!isset($p->$k)) {\r
+ continue;\r
+ }\r
+ $p->$k = $v;\r
+ }\r
+ $c->parametres = serialize($p);\r
+ $c->update('WHERE theme_id=\'' . $this->con->escape($data['theme_id']) . '\'');\r
+ if (file_exists(WS_THEMES . '/' . $data['theme_id'] . '.jpg')) {\r
+ unlink(WS_THEMES . '/' . $data['theme_id'] . '.jpg');\r
+ }\r
+ }\r
+\r
+ protected function getNextId()\r
+ {\r
+ $r = $this->con->select('SELECT MAX(theme_id) AS theme_id FROM themes');\r
+ if ($r->theme_id < 1000) {\r
+ return 1000;\r
+ }\r
+ return $r->theme_id + 1;\r
+ }\r
+\r
+ public function delete($theme_id, $onlyFiles = false)\r
+ {\r
+ if (is_null($theme_id) || $theme_id == '') {\r
+ return;\r
+ }\r
+ if (!$onlyFiles) {\r
+ $this->con->execute('DELETE FROM themes WHERE theme_id=\'' . $this->con->escape($theme_id) . '\'');\r
+ $api = new ws3API();\r
+ $api->deleteTheme($theme_id);\r
+ }\r
+ $fref = WS_THEMES . '/' . $theme_id;\r
+ if (file_exists($fref)) {\r
+ files::deltree($fref);\r
+ }\r
+ if (file_exists($fref . '.jpg')) {\r
+ unlink($fref . '.jpg');\r
+ }\r
+ }\r
+\r
+ public function rename($theme_id, $newname)\r
+ {\r
+ $c = $this->con->openCursor('themes');\r
+ $c->nom = $newname;\r
+ $c->update('WHERE theme_id=\'' . $this->con->escape($theme_id) . '\'');\r
+\r
+ $theme = $this->selectById($theme_id);\r
+ $theme->nom = $newname;\r
+ $api = new ws3API();\r
+ $api->updateTheme($theme);\r
+ }\r
+\r
+ public function duplicate($theme_id, $proprietaire)\r
+ {\r
+ if (is_null($theme_id) || $theme_id == '') {\r
+ return;\r
+ }\r
+ $theme = $this->selectById($theme_id);\r
+ // Copie des données\r
+ $c = $this->con->openCursor('themes');\r
+ $c->theme_id = $this->getNextId();\r
+ $c->nom = $theme->nom . ' (copy)';\r
+ $c->parametres = serialize($theme->parametres);\r
+ $c->signature = $theme->signature;\r
+ $c->icones = $theme->icones;\r
+ $c->proprietaire = $proprietaire;\r
+ $c->date = TIME;\r
+ $c->insert();\r
+\r
+ $this->delete($c->theme_id, true);\r
+ // Copie des fichiers\r
+ $from = WS_THEMES . '/' . $theme_id;\r
+ $to = WS_THEMES . '/' . $c->theme_id;\r
+ $dr = opendir($from);\r
+ if (!file_exists($to)) {\r
+ mkdir($to, 0777, true);\r
+ } else {\r
+ files::deltree($to);\r
+ mkdir($to, 0777, true);\r
+ } //.\r
+ while ($file = readdir($dr)) {\r
+ if ($file == '.' || $file == '..') {\r
+ continue;\r
+ }\r
+ copy($from . '/' . $file, $to . '/' . $file);\r
+ }\r
+ if (file_exists($from . '.jpg')) {\r
+ copy($from . '.jpg', $to . '.jpg');\r
+ }\r
+\r
+\r
+ $theme=$this->selectById($c->theme_id);\r
+ try {\r
+ $api = new ws3API();\r
+ $api->createTheme($theme);\r
+ }catch (Exception $e){\r
+ print_r($e);\r
+ exit;\r
+ }\r
+\r
+ return $theme;\r
+ }\r
+\r
+}
\ No newline at end of file