PageRenderTime 26ms CodeModel.GetById 8ms RepoModel.GetById 0ms app.codeStats 0ms

/_plugins_/spip-plans/inc/plans_classes.php

https://bitbucket.org/pombredanne/spip-zone-treemap
PHP | 301 lines | 223 code | 44 blank | 34 comment | 46 complexity | 9a44eb356716f63c4e24ea455c46fed3 MD5 | raw file
  1. <?php
  2. /**
  3. * SPIP-Plans
  4. *
  5. * Copyright (c) 2006-2009
  6. * Agence Artégo http://www.artego.fr
  7. *
  8. * Ce programme est un logiciel libre distribue sous licence GNU/GPLv3.
  9. * Pour plus de details voir http://www.gnu.org/licenses/gpl-3.0.html
  10. *
  11. **/
  12. include_spip('plans_fonctions');
  13. /**
  14. * plan
  15. *
  16. * @copyright 2006-2009 Artégo
  17. */
  18. class plan {
  19. var $id_plan;
  20. var $titre;
  21. var $descriptif;
  22. var $maj;
  23. var $statut = 'hors_ligne';
  24. var $existe = false;
  25. /**
  26. * plan : constructeur
  27. *
  28. * @param int id_plan
  29. * @return void
  30. **/
  31. function plan($id_plan=-1) {
  32. $this->id_plan = $id_plan;
  33. if ($this->id_plan == -1) {
  34. $this->titre = _T('plans:nouveau_plan');
  35. } else {
  36. $res = sql_select('*', 'spip_plans', 'id_plan='.intval($this->id_plan));
  37. if (sql_count($res)) {
  38. $arr = sql_fetch($res);
  39. $this->titre = $arr['titre'];
  40. $this->descriptif = $arr['descriptif'];
  41. $this->maj = $arr['maj'];
  42. $this->statut = $arr['statut'];
  43. $this->existe = true;
  44. }
  45. }
  46. }
  47. function enregistrer() {
  48. if ($this->id_plan == -1) {
  49. $champs = array(
  50. 'titre' => $this->titre,
  51. 'descriptif' => $this->descriptif,
  52. 'maj' => 'NOW()',
  53. 'statut' => 'hors_ligne'
  54. );
  55. $this->id_plan = sql_insertq('spip_plans', $champs);
  56. $this->existe = true;
  57. } else {
  58. $champs = array(
  59. 'titre' => $this->titre,
  60. 'descriptif' => $this->descriptif,
  61. 'date' => 'NOW()'
  62. );
  63. sql_updateq('spip_plans', $champs, 'id_plan='.intval($this->id_plan));
  64. }
  65. }
  66. function enregistrer_statut($statut) {
  67. switch ($statut) {
  68. case 'hors_ligne':
  69. sql_updateq('spip_plans', array('statut' => 'hors_ligne', 'maj' => 'NOW()'), 'id_plan='.intval($this->id_plan));
  70. $redirection = generer_url_ecrire('plans', 'id_plan='.$this->id_plan, true);
  71. break;
  72. case 'en_ligne':
  73. sql_updateq('spip_plans', array('statut' => 'en_ligne', 'maj' => 'NOW()'), 'id_plan='.intval($this->id_plan));
  74. $redirection = generer_url_ecrire('plans', 'id_plan='.$this->id_plan, true);
  75. break;
  76. case 'poubelle':
  77. $this->supprimer();
  78. $redirection = generer_url_ecrire('plans_tous');
  79. break;
  80. }
  81. return $redirection;
  82. }
  83. function ajouter_logo($fichier, $type) {
  84. $chemin_fichier = $fichier['tmp_name'];
  85. $mime = $fichier['type'];
  86. $logo = '';
  87. if ($mime == 'image/jpeg') {
  88. $logo = _DIR_IMG.'plan'.$type.$this->id_plan.'.jpg';
  89. }
  90. if (strcmp($mime, 'image/png') == 0) {
  91. $logo = _DIR_IMG.'plan'.$type.$this->id_plan.'.png';
  92. }
  93. if (strcmp($mime, 'image/gif') == 0) {
  94. $logo = _DIR_IMG.'plan'.$type.$this->id_plan.'.gif';
  95. }
  96. if (!empty($logo)) {
  97. move_uploaded_file($chemin_fichier, $logo);
  98. }
  99. }
  100. function calculer_nb_points() {
  101. return sql_countsel('spip_points', 'id_plan='.intval($this->id_plan));
  102. }
  103. function supprimer() {
  104. $this->supprimer_points();
  105. sql_delete('spip_points', 'id_plan='.intval($this->id_plan));
  106. // suppression logos
  107. $logo_f = charger_fonction('chercher_logo', 'inc');
  108. if ($logo_on = $logo_f($this->id_plan, 'id_plan', 'on'))
  109. unlink($logo_on[0]);
  110. if ($logo_off = $logo_f($this->id_plan, 'id_plan', 'off'))
  111. unlink($logo_off[0]);
  112. sql_delete('spip_plans', 'id_plan='.intval($this->id_plan));
  113. sql_delete('spip_mots_plans', 'id_plan='.intval($this->id_plan));
  114. }
  115. function supprimer_points() {
  116. $res = sql_select('id_plan, id_point', 'spip_points', 'id_plan='.intval($this->id_plan));
  117. while ($arr = sql_fetch($res)) {
  118. $point = new point($arr['id_plan'], $arr['id_point']);
  119. $point->supprimer();
  120. }
  121. }
  122. }
  123. /**
  124. * point
  125. *
  126. * @copyright 2006-2009 Artégo
  127. */
  128. class point {
  129. var $id_point;
  130. var $id_plan;
  131. var $titre;
  132. var $lien;
  133. var $descriptif;
  134. var $abscisse;
  135. var $ordonnee;
  136. var $z_index;
  137. var $existe = false;
  138. /**
  139. * point : constructeur
  140. *
  141. * @param int id_point
  142. * @return void
  143. **/
  144. function point($id_plan, $id_point=-1) {
  145. $this->id_point = $id_point;
  146. $this->id_plan = $id_plan;
  147. if ($this->id_point == -1) {
  148. $this->titre = _T('plans:nouveau_point');
  149. $this->z_index = sql_countsel('spip_points', 'id_plan='.intval($this->id_plan));
  150. } else {
  151. $res = sql_select('*', 'spip_points', 'id_point='.intval($this->id_point).' AND id_plan='.intval($this->id_plan));
  152. if (sql_count($res)) {
  153. $arr = sql_fetch($res);
  154. $this->titre = $arr['titre'];
  155. $this->lien = $arr['lien'];
  156. $this->descriptif = $arr['descriptif'];
  157. $this->abscisse = $arr['abscisse'];
  158. $this->ordonnee = $arr['ordonnee'];
  159. $this->z_index = $arr['z_index'];
  160. $this->existe = true;
  161. }
  162. }
  163. }
  164. function enregistrer() {
  165. if ($this->id_point == -1) {
  166. $this->z_index = sql_countsel('spip_points', 'id_plan='.intval($this->id_plan));
  167. $champs = array(
  168. 'id_plan' => intval($this->id_plan),
  169. 'titre' => $this->titre,
  170. 'lien' => $this->lien,
  171. 'descriptif' => $this->descriptif,
  172. 'abscisse' => intval($this->abscisse),
  173. 'ordonnee' => intval($this->ordonnee),
  174. 'z_index' => intval($this->z_index)
  175. );
  176. $this->id_point = sql_insertq('spip_points', $champs);
  177. $this->existe = true;
  178. } else {
  179. $champs = array(
  180. 'id_plan' => intval($this->id_plan),
  181. 'titre' => $this->titre,
  182. 'lien' => $this->lien,
  183. 'descriptif' => $this->descriptif,
  184. 'abscisse' => intval($this->abscisse),
  185. 'ordonnee' => intval($this->ordonnee)
  186. );
  187. sql_updateq('spip_points', $champs, 'id_point='.intval($this->id_point));
  188. }
  189. sql_updateq('spip_plans', array('maj' => 'NOW()'), 'id_plan='.intval($this->id_plan));
  190. }
  191. function supprimer() {
  192. $this->enregistrer_z_index('tout_au_dessus');
  193. // suppression logos
  194. $logo_f = charger_fonction('chercher_logo', 'inc');
  195. if ($logo_on = $logo_f($this->id_point, 'id_point', 'on'))
  196. unlink($logo_on[0]);
  197. if ($logo_off = $logo_f($this->id_point, 'id_point', 'off'))
  198. unlink($logo_off[0]);
  199. sql_delete('spip_points', 'id_point='.intval($this->id_point));
  200. sql_updateq('spip_plans', array('maj' => 'NOW()'), 'id_plan='.intval($this->id_plan));
  201. }
  202. function ajouter_logo($fichier, $type) {
  203. $chemin_fichier = $fichier['tmp_name'];
  204. $mime = $fichier['type'];
  205. $logo = '';
  206. if ($mime == 'image/jpeg') {
  207. $logo = _DIR_IMG.'point'.$type.$this->id_point.'.jpg';
  208. }
  209. if (strcmp($mime, 'image/png') == 0) {
  210. $logo = _DIR_IMG.'point'.$type.$this->id_point.'.png';
  211. }
  212. if (strcmp($mime, 'image/gif') == 0) {
  213. $logo = _DIR_IMG.'point'.$type.$this->id_point.'.gif';
  214. }
  215. if (!empty($logo)) {
  216. if (file_exists($logo))
  217. unlink($logo);
  218. move_uploaded_file($chemin_fichier, $logo);
  219. }
  220. }
  221. function enregistrer_z_index($position) {
  222. $resultat_tous_les_points = sql_select('id_point', 'spip_points', 'id_plan='.intval($this->id_plan).' AND id_point!='.intval($this->id_point), '', 'z_index');
  223. if ($position === 'tout_au_dessus') {
  224. $tableau_points = array();
  225. while ($arr = sql_fetch($resultat_tous_les_points)) {
  226. $tableau_points[] = $arr['id_point'];
  227. }
  228. $tableau_final = array_merge($tableau_points, array($this->id_point));
  229. } else if ($position == 0) {
  230. $tableau_points = array();
  231. while ($arr = sql_fetch($resultat_tous_les_points)) {
  232. $tableau_points[] = $arr['id_point'];
  233. }
  234. $tableau_final = array_merge(array($this->id_point), $tableau_points);
  235. } else {
  236. $i = 0;
  237. $tableau_points_avant = array();
  238. $tableau_points_apres = array();
  239. $deuxieme_tableau = false;
  240. while ($arr = sql_fetch($resultat_tous_les_points)) {
  241. if ($position == $i)
  242. $deuxieme_tableau = true;
  243. if ($deuxieme_tableau)
  244. $tableau_points_apres[] = $arr['id_point'];
  245. else
  246. $tableau_points_avant[] = $arr['id_point'];
  247. $i++;
  248. }
  249. $tableau_final = array_merge($tableau_points_avant, array($this->id_point), $tableau_points_apres);
  250. }
  251. foreach ($tableau_final as $cle => $valeur) {
  252. sql_update('spip_points', array('z_index' => $cle), 'id_point='.intval($valeur));
  253. }
  254. sql_updateq('spip_plans', array('maj' => 'NOW()'), 'id_plan='.intval($this->id_plan));
  255. }
  256. }
  257. ?>