[ Index ]
 

Code source de SPIP Agora 1.4

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/Agora1-4/ecrire/include/bd/ -> newsletter.php (source)

   1  <?php
   2  /*****************************************************
   3  * This file is part of Agora, web based content management system.
   4  *
   5  * Agora is free software; you can redistribute it and/or modify
   6  * it under the terms of the GNU General Public License as published by
   7  * the Free Software Foundation; version 2 of the License.
   8  *
   9  * Agora is distributed in the hope that it will be useful,
  10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12  * GNU General Public License for more details (file "COPYING").
  13  *
  14  * Copyright © Arnaud Martin, Antoine Pitrou et Philippe Rivière.
  15  * List of authors detailed in "copyright_fr.html" file.
  16  * E-mail : agora@sig.premier-ministre.gouv.fr
  17  * Web site : http://www.agora.gouv.fr
  18  *****************************************************/
  19  // Base class for Article business persistence abstraction.
  20  //
  21  if (defined("_BD_NEWSLETTER"))
  22      return;
  23  
  24  define("_BD_NEWSLETTER", "1");
  25  
  26  require_once("PEAR.php");
  27  require_once("DB.php");
  28  require_once dirname(__FILE__). "/metier.php";
  29  require_once dirname(__FILE__). "/../../inc_filtres.php";
  30  require_once dirname(__FILE__). "/../../inc_meta.php";
  31  
  32  define("NEWSLETTER_ALL_FIELDS",
  33         ' lst_id, lst_name, lst_comment, lst_moderation, lst_moderator_email, ' . 'lst_subscribe_subject, lst_subscribe_text, lst_subject, ' . 'lst_unsubscribe_subject, lst_unsubscribe_text, lst_subject_tag, ' . 'lst_html_skeleton, lst_text_skeleton, lst_nb_articles ');
  34  
  35  /**
  36   * BD_newsletter is a base class for newsletter business persistence abstraction implementations, and must be
  37   * inherited by all such.
  38   * @package    BD
  39   * @author  Antoine Angénieux <aangenieux@clever-age.com>
  40   * @author     Erwan Le Bescond <elebescond@clever-age.com>
  41   * @access    public
  42   */
  43  class BD_newsletter extends BD_metier {
  44  
  45      // {{{ properties
  46  
  47      var $_id;
  48      var $_name;
  49      var $_comment;
  50      var $_moderation;
  51      var $_moderatorEmail;
  52      var $_subscribeSubject;
  53      var $_subscribeText;
  54      var $_subject;
  55      var $_unsubscribeSubject;
  56      var $_unsubscribeText;
  57      var $_subjectTag;
  58      var $_htmlSkeleton;
  59      var $_textSkeleton;
  60      var $_nbArticles;
  61  
  62      // }}}
  63  
  64      // {{{ factory()
  65      function &factory ($dbParameters = null, $dbOptions = null) {
  66          if (file_exists(
  67                  dirname(__FILE__). "/" . $dbParameters->_dbEngine . "/newsletter_" . $dbParameters->_dbEngine . ".php")
  68              == false) {
  69              include_once(dirname(__FILE__). "/common/newsletter_common.php");
  70              $classname = "BD_newsletter_common";
  71          }
  72          else {
  73              include_once(
  74                  dirname(__FILE__). "/" . $dbParameters->_dbEngine . "/newsletter_" . $dbParameters->_dbEngine . ".php");
  75              $classname = "BD_newsletter_" . $dbParameters->_dbEngine;
  76          }
  77  
  78          if (!class_exists($classname)) {
  79              return PEAR::raiseError("Cannot instanciate class $classname", null, null, null, null, null, false);
  80          }
  81  
  82          $obj = &new $classname;
  83  
  84          $result = $obj->setDbParameters($dbParameters);
  85  
  86          if ($dbOptions != null) {
  87              $obj->setDbOptions($dbOptions);
  88          }
  89  
  90          if (PEAR::isError($result)) {
  91              return $result;
  92          }
  93          else {
  94              return $obj;
  95          }
  96      }
  97  
  98      // }}}
  99  
 100      // {{{ constructor
 101  
 102      /**
 103       * DB_newsletter constructor.
 104       *
 105       * @access public
 106       */
 107  
 108  	function BD_newsletter () { }
 109  
 110      // }}}
 111  
 112      // {{{ getId()
 113  
 114  	function getId () {
 115          return $this->_id;
 116      }
 117  
 118      // }}}
 119  
 120      // {{{ setId()
 121  
 122  	function setId ($id) {
 123          $this->_id = $id;
 124      }
 125  
 126      // }}}
 127  
 128      // {{{ getName()
 129  
 130  	function getName () {
 131          return stripslashes($this->_name);
 132      }
 133  
 134      // }}}
 135  
 136      // {{{ setName()
 137  
 138  	function setName ($name) {
 139          $this->_name = addslashes(corriger_caracteres($name));
 140      }
 141  
 142      // }}}
 143  
 144      // {{{ getComment()
 145  
 146  	function getComment () {
 147          return stripslashes($this->_comment);
 148      }
 149  
 150      // }}}
 151  
 152      // {{{ setComment()
 153  
 154  	function setComment ($comment) {
 155          $this->_comment = addslashes(corriger_caracteres($comment));
 156      }
 157  
 158      // }}}
 159  
 160      // {{{ getModeration()
 161  
 162  	function getModeration () {
 163          return $this->_moderation;
 164      }
 165  
 166      // }}}
 167  
 168      // {{{ setModeration()
 169  
 170  	function setModeration ($moderation) {
 171          $this->_moderation = $moderation;
 172      }
 173  
 174      // }}}
 175  
 176      // {{{ getModeratorEmail()
 177  
 178  	function getModeratorEmail () {
 179          return stripslashes($this->_moderatorEmail);
 180      }
 181  
 182      // }}}
 183  
 184      //{{{ setModeratorEmail()
 185  
 186  	function setModeratorEmail ($moderatorEmail) {
 187          $this->_moderatorEmail = addslashes(corriger_caracteres($moderatorEmail));
 188      }
 189  
 190      // }}}
 191  
 192      // {{{ getSubscribeSubject()
 193  
 194  	function getSubscribeSubject () {
 195          return stripslashes($this->_subscribeSubject);
 196      }
 197  
 198      // }}}
 199  
 200      // {{{ setSubscribeSubject()
 201  
 202  	function setSubscribeSubject ($subscribeSubject) {
 203          $this->_subscribeSubject = addslashes(corriger_caracteres($subscribeSubject));
 204      }
 205  
 206      // }}}
 207  
 208      // {{{ getSubscribeText()
 209  
 210  	function getSubscribeText () {
 211          return stripslashes($this->_subscribeText);
 212      }
 213  
 214      // }}}
 215  
 216      // {{{ setSubscribeText()
 217  
 218  	function setSubscribeText ($subscribeTexte) {
 219          $this->_subscribeText = addslashes(corriger_caracteres($subscribeTexte));
 220      }
 221  
 222      // }}}
 223  
 224      // {{{ getSubject()
 225  
 226  	function getSubject () {
 227          return stripslashes($this->_subject);
 228      }
 229  
 230      // }}}
 231  
 232      // {{{ setSubject()
 233  
 234  	function setSubject ($subject) {
 235          $this->_subject = addslashes(corriger_caracteres($subject));
 236      }
 237  
 238      // }}}
 239  
 240      // {{{ getUnsubscribeSubject()
 241  
 242  	function getUnsubscribeSubject () {
 243          return stripslashes($this->_unsubscribeSubject);
 244      }
 245  
 246      // }}}
 247  
 248      // {{{ setUnsubscribeSubject()
 249  
 250  	function setUnsubscribeSubject ($unsubscribeSubject) {
 251          $this->_unsubscribeSubject = addslashes(corriger_caracteres($unsubscribeSubject));
 252      }
 253  
 254      // }}}
 255  
 256      // {{{ getUnsubscribeText()
 257  
 258  	function getUnsubscribeText () {
 259          return stripslashes($this->_unsubscribeText);
 260      }
 261  
 262      // }}}
 263  
 264      // {{{ setUnsubscribeText()
 265  
 266  	function setUnsubscribeText ($unsubscribeTexte) {
 267          $this->_unsubscribeText = addslashes(corriger_caracteres($unsubscribeTexte));
 268      }
 269  
 270      // }}}
 271  
 272      // {{{ getSubjectTag()
 273  
 274  	function getSubjectTag () {
 275          return $this->_subjectTag;
 276      }
 277  
 278      // }}}
 279  
 280      // {{{ setSubjectTag()
 281  
 282  	function setSubjectTag ($subjectTag) {
 283          $this->_subjectTag = $subjectTag;
 284      }
 285  
 286      // }}}
 287  
 288      // {{{ getHtmlSkeleton()
 289  
 290  	function getHtmlSkeleton () {
 291          return $this->_htmlSkeleton;
 292      }
 293  
 294      // }}}
 295  
 296      // {{{ setHtmlSkeleton()
 297  
 298  	function setHtmlSkeleton ($htmlSkeleton) {
 299          $this->_htmlSkeleton = $htmlSkeleton;
 300      }
 301  
 302      // }}}
 303  
 304      // {{{ getTextSkeleton()
 305  
 306  	function getTexteSkeleton () {
 307          return $this->_textSkeleton;
 308      }
 309  
 310      // }}}
 311  
 312      // {{{ setTextSkeleton()
 313  
 314  	function setTextSkeleton ($textSkeleton) {
 315          $this->_textSkeleton = $textSkeleton;
 316      }
 317  
 318      // }}}
 319  
 320      // {{{ getNbArticles()
 321  
 322  	function getNbArticles () {
 323          return $this->_nbArticles;
 324      }
 325  
 326      // }}}
 327  
 328      // {{{ setNbArticles()
 329  
 330  	function setNbArticles ($nbArticles) {
 331          $this->_nbArticles = $nbArticles;
 332      }
 333  
 334      // }}}
 335  
 336      // {{{ create()
 337  
 338  	function create () {
 339          $db = &$this->_getDB();
 340          $string_prefix = $GLOBALS['table_prefix']. "_cm_lists";
 341          $newsletterId = $db->nextId($string_prefix, true);
 342  
 343          if (DB::isError($newsletterId)) {
 344              return $newsletterId;
 345          }
 346  
 347          $this->_id = $newsletterId;
 348  
 349          if ($this->_nbArticles == NULL)
 350              $this->_nbArticles = 0;
 351  
 352          $query
 353              = 'INSERT INTO ' . $GLOBALS['table_prefix']. '_cm_lists (' . NEWSLETTER_ALL_FIELDS . ') VALUES ' . "('" . $this->_id . "', " . "'" . $this->_name . "', " . "'" . $this->_comment . "', " . "'" . $this->_moderation . "', " . "'" . $this->_moderatorEmail . "', " . "'" . $this->_subscribeSubject . "', " . "'" . $this->_subscribeText . "', " . "'" . $this->_subject . "', " . "'" . $this->_unsubscribeSubject . "', " . "'" . $this->_unsubscribeText . "', " . "'" . $this->_subjectTag . "', " . "'" . $this->_htmlSkeleton . "', " . "'" . $this->_textSkeleton . "', " . "'" . $this->_nbArticles . "') ";
 354          //die($query);
 355  
 356          $result = $db->query($query);
 357  
 358          if (DB::isError($result)) {
 359              die($result->getMessage());
 360              return $result;
 361          }
 362      }
 363  
 364      // }}}
 365  
 366      // {{{ update()
 367  
 368  	function update () {
 369          $db = &$this->_getDB();
 370          $query
 371              = "UPDATE " . $GLOBALS['table_prefix']. "_cm_lists SET " . "lst_name = '" . $this->_name . "'" . ", lst_comment= '" . $this->_comment . "'" . ", lst_moderation= '" . $this->_moderation . "'" . ", lst_moderator_email= '" . $this->_moderatorEmail . "'" . ", lst_subscribe_subject= '" . $this->_subscribeSubject . "'" . ", lst_subscribe_text= '" . $this->_subscribeText . "'" . ", lst_subject= '" . $this->_subject . "'" . ", lst_unsubscribe_subject= '" . $this->_unsubscribeSubject . "'" . ", lst_unsubscribe_text= '" . $this->_unsubscribeText . "'" . ", lst_subject_tag= '" . $this->_subjectTag . "'" . ", lst_html_skeleton= '" . $this->_htmlSkeleton . "'" . ", lst_text_skeleton= '" . $this->_textSkeleton . "'" . ", lst_nb_articles= '" . $this->_nbArticles . "'" . " WHERE lst_id = " . $this->_id;
 372  
 373          //echo '<br>' . $query . '<br>';
 374  
 375          $result = $db->query($query);
 376  
 377          if (DB::isError($result)) {
 378              die($result->getMessage());
 379          }
 380      }
 381  
 382      // }}}
 383  
 384      // {{{ load()
 385  
 386  	function load ($idNewsletter) {
 387          $db = &$this->_getDB();
 388  
 389          if (DB::isError($db)) {
 390              return $db;
 391          }
 392  
 393          $query
 394              = "SELECT" . NEWSLETTER_ALL_FIELDS . "FROM " . $GLOBALS['table_prefix']. "_cm_lists WHERE lst_id = $idNewsletter";
 395          //echo '<br>' . $query .  '<br>';
 396  
 397          $result = $db->query($query);
 398  
 399          if (DB::isError($result)) {
 400              return $result;
 401          }
 402          else {
 403              if ($row = $result->fetchRow()) {
 404                  $this->_fetchData($row);
 405              }
 406              else {
 407                  return PEAR::raiseError(
 408                             "[" . get_class(
 409                                       $this). " DB_newsletter : load($idNewsletter)] Aucune lettre d'information ne correspond à cet ID!",
 410                             null,
 411                             null,
 412                             null,
 413                             null,
 414                             null,
 415                             false);
 416              }
 417              $result->free();
 418          }
 419      }
 420  
 421      // }}}
 422  
 423      // {{{ delete()
 424  
 425  	function delete ($id) {
 426          $db = &$this->_getDB();
 427  
 428          if (DB::isError($db)) {
 429              return $db;
 430          }
 431  
 432          $query = "DELETE FROM " . $GLOBALS['table_prefix']. "_cm_lists WHERE lst_id = $id";
 433  
 434          // ATTENTION, SI CETTE FONCTIONNALITE EST IMPLEMTENTEE, PENSEZ A SUPPRIMER TOUTES LES REFERENCES
 435          // A CETTE LISTE!!
 436  
 437          $result = $db->query($query);
 438  
 439          if (DB::isError($result)) {
 440              return $result;
 441          }
 442      }
 443  
 444      // }}}
 445  
 446      // {{{ getListsForModeration($moderation)
 447  
 448  	function getListsForModeration ($moderation) {
 449          $db = &$this->_getDB();
 450  
 451          if (DB::isError($db)) {
 452              return PEAR::raiseError(
 453                         "[" . get_class($this). " BD_newsletter : getListsForModeration()] " . $db->getMessage(). "",
 454                         null,
 455                         null,
 456                         null,
 457                         null,
 458                         null,
 459                         false);
 460          }
 461  
 462          $query
 463              = "SELECT " . NEWSLETTER_ALL_FIELDS . " FROM " . $GLOBALS['table_prefix']. "_cm_lists WHERE lst_moderation != '$moderation' ORDER BY lst_name";
 464  
 465          $queryResult = $db->query($query);
 466  
 467          $newsletters = array();
 468  
 469          if (DB::isError($result)) {
 470              return PEAR::raiseError(
 471                         "[" . get_class($this). " BD_newsletter : getListsForModeration()] " . $result->getMessage(). "",
 472                         null,
 473                         null,
 474                         null,
 475                         null,
 476                         null,
 477                         false);
 478          }
 479          else {
 480              while ($row = $queryResult->fetchRow()) {
 481                  $resultNewsletter = &BD_newsletter::factory($this->getDbParameters(), $this->getDbOptions());
 482                  $resultNewsletter->_fetchData($row);
 483                  $newsletters[] = &$resultNewsletter;
 484              }
 485              $queryResult->free();
 486          }
 487  
 488          return $newsletters;
 489      }
 490  
 491      // }}}
 492  
 493      // {{{ _fetchData()
 494  
 495  	function _fetchData ($row) {
 496          $this->setId($row['lst_id']);
 497          $this->setName($row['lst_name']);
 498          $this->setComment($row['lst_comment']);
 499          $this->setModeration($row['lst_moderation']);
 500          $this->setModeratorEmail($row['lst_moderator_email']);
 501          $this->setSubscribeSubject($row['lst_subscribe_subject']);
 502          $this->setSubscribeText($row['lst_subscribe_text']);
 503          $this->setSubject($row['lst_subject']);
 504          $this->setUnsubscribeSubject($row['lst_unsubscribe_subject']);
 505          $this->setUnsubscribeText($row['lst_unsubscribe_text']);
 506          $this->setSubjectTag($row['lst_subject_tag']);
 507          $this->setHtmlSkeleton($row['lst_html_skeleton']);
 508          $this->setTextSkeleton($row['lst_text_skeleton']);
 509          $this->setNbArticles($row['lst_nb_articles']);
 510      }
 511  
 512  // }}}
 513  
 514  }
 515  ?>


Généré le : Sat Feb 24 14:40:03 2007 par Balluche grâce à PHPXref 0.7