[ Index ]
 

Code source de eGroupWare 1.2.106-2

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

title

Body

[fermer]

/polls/inc/ -> class.bo.inc.php (source)

   1  <?php
   2      /**************************************************************************\
   3      * eGroupWare - Polls                                                       *
   4      * http://www.egroupware.org                                                *
   5      * Copyright (c) 1999 Till Gerken (tig@skv.org)                             *
   6      * Modified by Greg Haygood (shrykedude@bellsouth.net)                      *
   7      * -----------------------------------------------                          *
   8      *  This program is free software; you can redistribute it and/or modify it *
   9      *  under the terms of the GNU General Public License as published by the   *
  10      *  Free Software Foundation; either version 2 of the License, or (at your  *
  11      *  option) any later version.                                              *
  12      \**************************************************************************/
  13  
  14      /* $Id: class.bo.inc.php 19418 2005-10-14 16:10:00Z ralfbecker $ */
  15  
  16      class bo
  17      {
  18          var $so;
  19          var $debug = false;
  20  
  21          var $start  = 0;
  22          var $query  = '';
  23          var $sort   = '';
  24          var $order  = '';
  25          var $filter = 0;
  26          var $limit  = 0;
  27          var $total  = 0;
  28  
  29          var $public_functions = array(
  30              'user_can_vote' => True,
  31              'view_results'  => True,
  32              'generate_ui'   => True,
  33              'get_list'      => True,
  34              'add_vote'      => True,
  35              'get_poll_data' => True,
  36              'somebusinessfunc' => True,
  37          );
  38  
  39          function bo($session=False)
  40          {
  41              $this->so =& CreateObject('polls.so');
  42              $this->load_settings();
  43  
  44              if($session)
  45              {
  46                  $this->read_sessiondata();
  47                  $this->use_session = True;
  48              }
  49  
  50              $_start  = get_var('start',array('POST','GET'));
  51              $_query  = get_var('query',array('POST','GET'));
  52              $_sort   = get_var('sort',array('POST','GET'));
  53              $_order  = get_var('order',array('POST','GET'));
  54              $_limit  = get_var('limit',array('POST','GET'));
  55              $_filter = get_var('filter',array('POST','GET'));
  56  
  57              if(isset($_start))
  58              {
  59                  if($this->debug) { echo '<br>overriding $start: "' . $this->start . '" now "' . $_start . '"'; }
  60                  $this->start = $_start;
  61              }
  62  
  63              if($_limit)
  64              {
  65                  $this->limit = $_limit;
  66              }
  67              else
  68              {
  69                  $this->limit = $GLOBALS['egw_info']['user']['preferences']['common']['maxmatchs'];
  70              }
  71  
  72              if((empty($_query) && !empty($this->query)) || !empty($_query))
  73              {
  74                  $this->query = $_query;
  75              }
  76  
  77              if(!empty($_sort))
  78              {
  79                  if($this->debug) { echo '<br>overriding $sort: "' . $this->sort . '" now "' . $_sort . '"'; }
  80                  $this->sort   = $_sort;
  81              }
  82              else
  83              {
  84                  $this->sort = 'ASC';
  85              }
  86  
  87              if(!empty($_order))
  88              {
  89                  if($this->debug) { echo '<br>overriding $order: "' . $this->order . '" now "' . $_order . '"'; }
  90                  $this->order = $_order;
  91              }
  92              else
  93              {
  94                  $this->order = 'poll_title';
  95              }
  96  
  97              if(!empty($_filter))
  98              {
  99                  if($this->debug) { echo '<br>overriding $filter: "' . $this->filter . '" now "' . $_filter . '"'; }
 100                  $this->filter = $_filter;
 101              }
 102  
 103          }
 104  
 105  		function load_settings()
 106          {
 107              $this->so->load_settings();
 108          }
 109  
 110  		function save_settings($data)
 111          {
 112              if(isset($data) && is_array($data))
 113              {
 114                  $this->so->save_settings($data);
 115              }
 116          }
 117  
 118  		function save_sessiondata($data = '')
 119          {
 120              if($this->use_session)
 121              {
 122                  if(empty($data) || !is_array($data))
 123                  {
 124                      $data = array();
 125                  }
 126                  $data += array(
 127                      'start'  => $this->start,
 128                      'order'  => $this->order,
 129                      'limit'  => $this->limit,
 130                      'query'  => $this->query,
 131                      'sort'   => $this->sort,
 132                      'filter' => $this->filter
 133                  );
 134                  if($this->debug) { echo '<br>Save:'; _debug_array($data); }
 135                  $GLOBALS['egw']->session->appsession('session_data','polls_list',$data);
 136              }
 137          }
 138  
 139  		function read_sessiondata()
 140          {
 141              $data = $GLOBALS['egw']->session->appsession('session_data','polls_list');
 142              if($this->debug) { echo '<br>Read:'; _debug_array($data); }
 143  
 144              $this->start  = $data['start'];
 145              $this->limit  = $data['limit'];
 146              $this->query  = $data['query'];
 147              $this->sort   = $data['sort'];
 148              $this->order  = $data['order'];
 149              $this->filter = $data['filter'];
 150          }
 151  
 152  		function somebusinessfunc()
 153          {
 154              //nothing to be added yet
 155          }
 156  
 157  		function add_vote($poll_id,$vote_id,$user_id)
 158          {
 159              if(isset($poll_id) && isset($vote_id) &&
 160                  (int)$poll_id >= 0 && (int)$vote_id >= 0)
 161              {
 162                  $this->so->add_vote($poll_id,$vote_id,$user_id);
 163              }
 164          }
 165  
 166  		function add_answer($poll_id,$answer)
 167          {
 168              $this->so->add_answer($poll_id,$answer);
 169          }
 170  
 171  		function add_question()
 172          {
 173              $question = $_POST['question'];
 174              if(!empty($question))
 175              {
 176                  $this->so->add_question($question);
 177                  return $this->so->get_last_added_poll();
 178              }
 179          }
 180  
 181  		function delete_answer($poll_id,$vote_id)
 182          {
 183              if(!empty($poll_id) && !empty($vote_id))
 184              {
 185                  $this->so->delete_answer($poll_id,$vote_id);
 186              }
 187          }
 188  
 189  		function delete_question($poll_id)
 190          {
 191              if(!empty($poll_id))
 192              {
 193                  $this->so->delete_question($poll_id);
 194              }
 195          }
 196  
 197  		function update_answer($poll_id,$vote_id,$answer)
 198          {
 199              if(!empty($poll_id) && !empty($vote_id) && isset($answer))
 200              {
 201                  $this->so->update_answer($poll_id,$vote_id,$answer);
 202              }
 203          }
 204  
 205  		function update_question($poll_id,$question)
 206          {
 207              if(!empty($poll_id) && isset($question))
 208              {
 209                  $this->so->update_question($poll_id,$question);
 210              }
 211          }
 212  
 213  		function get_latest_poll()
 214          {
 215              return $this->so->get_latest_poll();
 216          }
 217  
 218  		function makelink($action,$args)
 219          {
 220              $menuaction = 'polls.uiadmin.'.$action;
 221              return $GLOBALS['egw']->link('/index.php',array('menuaction'=>$menuaction,$args));
 222          }
 223  
 224  		function user_can_vote($poll_id)
 225          {
 226              if($GLOBALS['poll_settings']['allow_multiple_votes'])
 227              {
 228                  return True;
 229              }
 230  
 231              $poll_id = (int)($poll_id);
 232              $votes = $this->so->get_user_votecount($poll_id);
 233  
 234              return ($votes == 0) ? True : False;
 235          }
 236  
 237  		function get_poll_title($poll_id)
 238          {
 239              return trim($this->so->get_poll_title($poll_id));
 240          }
 241  
 242  		function get_poll_total($poll_id)
 243          {
 244              $sum = (int)$this->so->get_poll_total($poll_id);
 245              return $sum >= 0 ? $sum : false;
 246          }
 247  
 248  		function get_poll_data($poll_id,$vote_id = -1)
 249          {
 250              return $this->so->get_poll_data($poll_id,$vote_id);
 251          }
 252  
 253  		function get_list($type = 'question', $returnall=false)
 254          {
 255              $ret = '';
 256              $options = array(
 257                  'start' => $this->start,
 258                  'query' => $this->query,
 259                  'sort'  => $this->sort,
 260                  'order' => $this->order
 261              );
 262              if(!$returnall)
 263              {
 264                  $options['limit'] = $this->limit;
 265              }
 266              if($type == 'question')
 267              {
 268                  $ret = $this->so->list_questions($options);
 269              }
 270              elseif($type == 'answer')
 271              {
 272                  $ret = $this->so->list_answers($options);
 273              }
 274              $this->total = $this->so->total;
 275              return $ret;
 276          }
 277      }
 278  ?>


Généré le : Sun Feb 25 17:20:01 2007 par Balluche grâce à PHPXref 0.7