XOOPS Docs - kernal
[ class tree: kernal ] [ index: kernal ] [ all elements ]

Source for file formselectuser.php

Documentation is available at formselectuser.php

  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. {
  21.     /**
  22.      * Constructor
  23.      *
  24.      * @param    string    $caption 
  25.      * @param    string    $name 
  26.      * @param    mixed    $value            Pre-selected value (or array of them).
  27.      *                                     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
  28.      * @param    bool    $include_anon    Include user "anonymous"?
  29.      * @param    int        $size            Number or rows. "1" makes a drop-down-list.
  30.      * @param    bool    $multiple       Allow multiple selections?
  31.      */
  32.     function XoopsFormSelectUser($caption$name$include_anon false$value null$size 1$multiple false)
  33.     {
  34.         $limit 200;
  35.         $select_element new XoopsFormSelect(""$name$value$size$multiple);
  36.         if ($include_anon{
  37.             $select_element->addOption(0$GLOBALS["xoopsConfig"]['anonymous']);
  38.         }
  39.         $member_handler =xoops_gethandler('member');
  40.         $user_count $member_handler->getUserCount();
  41.         $value is_array($value$value empty($valuearray(array($value) );
  42.         if ($user_count $limit && count($value0{
  43.             $criteria new CriteriaCompo(new Criteria("uid""(".implode(","$value).")""IN"));
  44.         else {
  45.             $criteria new CriteriaCompo();
  46.             $criteria->setLimit($limit);
  47.         }
  48.         $criteria->setSort('uname');
  49.         $criteria->setOrder('ASC');
  50.         $users $member_handler->getUserList($criteria);
  51.         $select_element->addOptionArray($users);
  52.         if ($user_count <= $limit{
  53.             $this->XoopsFormElementTray($caption""$name);
  54.             $this->addElement($select_element);
  55.             return;
  56.         }
  57.         
  58.         
  59.         if (!@include_once XOOPS_ROOT_PATH."/language/".$GLOBALS["xoopsConfig"]["language"]."/findusers.php"{
  60.             include_once XOOPS_ROOT_PATH."/language/english/findusers.php";
  61.         }
  62.         
  63.         $js_addusers =
  64.             "<script type=\"text/javascript\">
  65.             function addusers(opts){
  66.                 var num = opts.substring(0, opts.indexOf(\":\"));
  67.                 opts = opts.substring(opts.indexOf(\":\")+1, opts.length);
  68.                 var sel = xoopsGetElementById(\""$name ($multiple "[]" """\");
  69.                 var arr = new Array(num);
  70.                 for (var n=0; n < num; n++) {
  71.                     var nm = opts.substring(0, opts.indexOf(\":\"));
  72.                     opts = opts.substring(opts.indexOf(\":\")+1, opts.length);
  73.                     var val = opts.substring(0, opts.indexOf(\":\"));
  74.                     opts = opts.substring(opts.indexOf(\":\")+1, opts.length);
  75.                     var txt = opts.substring(0, nm - val.length);
  76.                     opts = opts.substring(nm - val.length, opts.length);
  77.                     var added = false;
  78.                     for (var k = 0; k < sel.options.length; k++) {
  79.                         if(sel.options[k].value == val){
  80.                             added = true;
  81.                             break;
  82.                         }
  83.                     }
  84.                     if (added == false) {
  85.                         sel.options[k] = new Option(txt, val);
  86.                         sel.options[k].selected = true;
  87.                     }
  88.                 }
  89.                 return true;
  90.             }
  91.             </script>";
  92.         
  93.         $token $GLOBALS['xoopsSecurity']->createToken();
  94.         $action_tray new XoopsFormElementTray(""" | ");
  95.         $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>"));
  96.         $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));
  97.  
  98.         $this->XoopsFormElementTray($caption"<br /><br />"$name);
  99.         $this->addElement($select_element);
  100.         $this->addElement($action_tray);
  101.     }
  102. }
  103. ?>

XOOPS Docs generated by phpDocumentor