[ Index ]
 

Code source de XOOPS 2.0.17.1

Accédez au Source d'autres logiciels libres

title

Body

[fermer]

/htdocs/class/xoopsform/ -> formselectuser.php (source)

   1  <?php
   2  /**

   3   * user select with page navigation

   4   *

   5   * limit: Only work with javascript enabled

   6   *

   7   * @copyright    The XOOPS project http://www.xoops.org/

   8   * @license        http://www.fsf.org/copyleft/gpl.html GNU public license

   9   * @author        Taiwen Jiang (phppp or D.J.) <php_pp@hotmail.com>

  10   * @since        1.00

  11   * @version        $Id: formselectuser.php 1052 2007-09-15 03:38:30Z phppp $

  12   * @package        kernal

  13   */
  14  if (!defined('XOOPS_ROOT_PATH')) {
  15      die("XOOPS root path not defined");
  16  }
  17  include_once XOOPS_ROOT_PATH."/class/xoopsform/formelementtray.php";
  18  include_once  XOOPS_ROOT_PATH."/class/xoopsform/formselect.php";
  19  
  20  class XoopsFormSelectUser extends XoopsFormElementTray
  21  {
  22      /**

  23       * Constructor

  24       *

  25       * @param    string    $caption

  26       * @param    string    $name

  27       * @param    mixed    $value            Pre-selected value (or array of them).

  28       *                                    For an item with massive members, such as "Registered Users", "$value" should be used to store selected temporary users only instead of all members of that item

  29       * @param    bool    $include_anon    Include user "anonymous"?

  30       * @param    int        $size            Number or rows. "1" makes a drop-down-list.

  31       * @param    bool    $multiple       Allow multiple selections?

  32       */
  33  	function XoopsFormSelectUser($caption, $name, $include_anon = false, $value = null, $size = 1, $multiple = false)
  34      {
  35          $limit = 200;
  36          $select_element = new XoopsFormSelect("", $name, $value, $size, $multiple);
  37          if ($include_anon) {
  38              $select_element->addOption(0, $GLOBALS["xoopsConfig"]['anonymous']);
  39          }
  40          $member_handler =& xoops_gethandler('member');
  41          $user_count = $member_handler->getUserCount();
  42          $value = is_array($value) ? $value : ( empty($value) ? array() : array($value) );
  43          if ($user_count > $limit && count($value) > 0) {
  44              $criteria = new CriteriaCompo(new Criteria("uid", "(".implode(",", $value).")", "IN"));
  45          } else {
  46              $criteria = new CriteriaCompo();
  47              $criteria->setLimit($limit);
  48          }
  49          $criteria->setSort('uname');
  50          $criteria->setOrder('ASC');
  51          $users = $member_handler->getUserList($criteria);
  52          $select_element->addOptionArray($users);
  53          if ($user_count <= $limit) {
  54              $this->XoopsFormElementTray($caption, "", $name);
  55              $this->addElement($select_element);
  56              return;
  57          }
  58          
  59          
  60          if (!@include_once XOOPS_ROOT_PATH."/language/".$GLOBALS["xoopsConfig"]["language"]."/findusers.php") {
  61              include_once XOOPS_ROOT_PATH."/language/english/findusers.php";
  62          }
  63          
  64          $js_addusers =
  65              "<script type=\"text/javascript\">
  66  		    function addusers(opts){
  67                  var num = opts.substring(0, opts.indexOf(\":\"));
  68                  opts = opts.substring(opts.indexOf(\":\")+1, opts.length);
  69                  var sel = xoopsGetElementById(\"". $name . ($multiple ? "[]" : "") . "\");
  70                  var arr = new Array(num);
  71                  for (var n=0; n < num; n++) {
  72                      var nm = opts.substring(0, opts.indexOf(\":\"));
  73                      opts = opts.substring(opts.indexOf(\":\")+1, opts.length);
  74                      var val = opts.substring(0, opts.indexOf(\":\"));
  75                      opts = opts.substring(opts.indexOf(\":\")+1, opts.length);
  76                      var txt = opts.substring(0, nm - val.length);
  77                      opts = opts.substring(nm - val.length, opts.length);
  78                      var added = false;
  79                      for (var k = 0; k < sel.options.length; k++) {
  80                          if(sel.options[k].value == val){
  81                              added = true;
  82                              break;
  83                          }
  84                      }
  85                      if (added == false) {
  86                          sel.options[k] = new Option(txt, val);
  87                          sel.options[k].selected = true;
  88                      }
  89                  }
  90                  return true;
  91              }
  92              </script>";
  93          
  94          $token = $GLOBALS['xoopsSecurity']->createToken();
  95          $action_tray = new XoopsFormElementTray("", " | ");
  96          $action_tray->addElement(new XoopsFormLabel('', "<a href='#' onclick='var sel = xoopsGetElementById(\"" . $name . ( $multiple ? "[]" : "" ) . "\");for (var i = sel.options.length-1; i >= 0; i--) {if (!sel.options[i].selected) {sel.options[i] = null;}}; return false;'>"._MA_USER_REMOVE."</a>"));
  97          $action_tray->addElement(new XoopsFormLabel('', "<a href='#' onclick='openWithSelfMain(\"".XOOPS_URL."/include/findusers.php?target={$name}&amp;multiple={$multiple}&amp;token={$token}\", \"userselect\", 800, 600, null); return false;' >"._MA_USER_MORE."</a>".$js_addusers));
  98  
  99          $this->XoopsFormElementTray($caption, "<br /><br />", $name);
 100          $this->addElement($select_element);
 101          $this->addElement($action_tray);
 102      }
 103  }
 104  ?>


Généré le : Sun Nov 25 11:44:32 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics