Beispiel #1
0
    public function orderGroupInfo($args) {
        if (!SecurityUtil::checkPermission('IWusers::', '::', ACCESS_READ)) {
            throw new Zikula_Exception_Fatal($this->__('No teniu autorització per accedir a aquesta informació.'));
        }       

        $orderBy = $this->request->request->get('orderBy', '');
        if ($orderBy=='') $orderBy = "gid";
        
        $gi = UserUtil::getGroups('',$orderBy);
        foreach ($gi as $key => $value) {
            $groupInfo[] = array_slice($value,0,2);
        }
       
        $view = Zikula_View::getInstance($this->name);
        $view->assign('groupInfo', $groupInfo);
        
        $content = $view->fetch('IWusers_groupsTable.tpl');
        return new Zikula_Response_Ajax(array('content' => $content));
    }
Beispiel #2
0
    public function main()
    {
        // Security check
        if (!SecurityUtil::checkPermission('SiriusXtecAuth::', '::', ACCESS_ADMIN)) {
            return LogUtil::registerPermissionError();
        }
        $MVars = ModUtil::getVar($this->name);
		$login_redirect = ModUtil::getVar('Users','login_redirect');
        $allGroups = UserUtil::getGroups();
        
        foreach ($allGroups as $key => $group) {
            
            if (in_array($key,$MVars['new_users_groups'])) {
                $allGroups[$key]['sel'] = 1;
            }else {
                $allGroups[$key]['sel'] = 0;
            }
        }
		$this->view->assign('login_redirect',$login_redirect);
        $this->view->assign('MVars', $MVars);
        $this->view->assign('allGroups',$allGroups);
        return $this->view->fetch('SiriusXtecAuth_admin_config.tpl');
    }
Beispiel #3
0
    /**
     * Import users from CSV file. 
     * @author Josep Ferràndiz Farré (jferran6@xtec.cat)
     * **CSV File header** Allowed fields: uname,new_uname,email,password,forcechgpass,activated,firstname,lastname1,lastname2,birthdate,gender,code,in,out
     * Fields "in" and "out" contains group IDs where the user will be added or removed, separated by "|" char
     * Deletions will be made before insertions.
     * 
     */
    public function import(){
        $this->throwForbiddenUnless(SecurityUtil::checkPermission('IWusers::', '::', ACCESS_ADMIN));
        // Sincronize tables users & IWUsers 
        ModUtil::apiFunc($this->name, 'admin', 'sincronize');
        $view = Zikula_View::getInstance($this->name);
        
        if ($this->request->isPost()) {
            $this->checkCsrfToken();
            $importFile = $this->request->files->get('importFile', null);
            $delimiter  = $this->request->request->get('delimiter', ';');
            // 1. Validate file: header & structure
            if (is_null($importFile)) {
                LogUtil::registerError($this->__('File error. Probably exceeds max. file size.'));
            } else {
                // Header fields table equivalents
                $headerTrans =array('uname'       => 'uname', 
                                    'new_uname'   => 'new_uname', 
                                    'email'       => 'email',
                                    'code'        => 'code',
                                    'password'    => 'password',
                                    'forcechgpass'=> 'forcechgpass',
                                    'activated'   => 'activated',
                                    'firstname'   => 'nom',
                                    'lastname1'   => 'cognom1',
                                    'lastname2'   => 'cognom2',
                                    'description' => 'description',
                                    'birthdate'   => 'naixement',
                                    'gender'      => 'sex',
                                    'in'          => 'in',
                                    'out'         => 'out'
                    );

                $import = new CsvImporter($importFile['tmp_name'],true, $headerTrans, $delimiter);  
                $header  = $import->getHeader();
                $oHeader = $import->getOriHeader();
                
                $check  = ModUtil::apiFunc($this->name, 'admin', 'checkCsvHeader', $header);
                // Check CSV file header
                if (!$check['correcte']) {
                    // CSV header incorrect
                    LogUtil::registerError($check['msg']);
                } else {
                    // Get CSV file content
                    $data = $import->get();
                    // Initialize 
                    $update = array();
                    $insert = array();
                    $optimizeGroups = ((in_array('in', $header)) || (in_array('out', $header)));
                    $forcechgpass   = in_array('forcechgpass', $header);
                    $iErrors = array();
                    // Check file info
                    foreach ($data as &$line) {
                        $uid = UserUtil::getIdFromName($line['uname']);
                        if ($optimizeGroups) {
                            $res = ModUtil::apiFunc($this->name, 'admin', 'optimizeGroups', array('uid' => $uid, 'data'=> $line));
                            $line['in'] = $res['in'];
                            $line['out'] = $res['out'];                            
                        }                            
                        if ($uid){       
                            $line['uid'] = $uid;
                            // Update
                            if (isset($line['activated'])){
                                if ($line['activated']!=""){
                                    $line['activated'] = $line['activated'] == '0' ? 0 : 1;                                    
                                } else {
                                    // Mantain actual value
                                    $line['activated'] = DBUtil::selectField('users', 'activated', 'uid='.$uid);
                                }                                
                            }
                            $update[] = $line;                                
                        } else {
                            // Insert new user
                            if ($line['uname'] !=""){
                                if (!isset($line['activated']) || (isset($line['activated']) && $line['activated']!='0')) $line['activated'] = 1;
                                $insert[] = $line;
                            } else {
                                // Error. No username 
                                $line['error'] = $this->__('No username.');
                                $iErrors[] = $line;
                            }
                        }                            
                    }
                    // Process file information
                    $allChanges = ModUtil::apiFunc($this->name, 'admin', 'applyCsvValues', array('update' => $update, 'insert' =>$insert));               
                    unset($update); $update = array();
                    unset($insert); $insert = array();
                    foreach ($allChanges as $user){                       
                        switch ($user['action']){
                            case 'm':
                                $update[] = $user;
                                break;
                            default:
                                $insert[] = $user;
                        }
                        if (isset($user['error'])){ 
                            // There are errors
                            $iErrors[] = $user;
                        }
                    }
                    $view->assign('insert', $insert);
                    $view->assign('update', $update);
                    $view->assign('iErrors', $iErrors);
                    $view->assign('header', $oHeader);
                    $view->assign('hc', count($oHeader));
                    return $view->fetch('IWusers_admin_importResults.tpl');        

                } // File header is correct
            } // exist import file                
        } // Is POST
         
        // Get zikula groups name and gid
        $g = UserUtil::getGroups('','name');
        foreach ($g as $key => $value) {
            $groupInfo[] = array_slice($value,0,2);
        }
                
        $view->assign('post_max_size', ini_get('post_max_size'));
        $view->assign('groupInfo', $groupInfo);
        
        return $view->fetch('IWusers_admin_import.tpl');        
    }
Beispiel #4
0
 /**
  * Return the html for the PN user group selector.
  *
  * @param string  $name          The selector name.
  * @param integer $selectedValue The currently selected value of the selector (optional) (default=0).
  * @param integer $defaultValue  The default value of the selector (optional) (default=0).
  * @param string  $defaultText   The text of the default value (optional) (default='').
  * @param integer $allValue      The value to assign for the "All" choice (optional) (default=0).
  * @param string  $allText       The text to display for the "All" choice (optional) (default='').
  * @param string  $excludeList   A (string) list of IDs to exclude (optional) (default=null).
  * @param boolean $submit        Whether or not to auto-submit the selector (optional) (default=false).
  * @param boolean $disabled      Whether or not to disable selector (optional) (default=false).
  * @param integer $multipleSize  The size to use for a multiple selector, 1 produces a normal/single selector (optional (default=1).
  *
  * @return The html for the user group selector.
  */
 public static function getSelector_Group($name = 'groupid', $selectedValue = 0, $defaultValue = 0, $defaultText = '', $allValue = 0, $allText = '', $excludeList = '', $submit = false, $disabled = false, $multipleSize = 1)
 {
     $data = array();
     $grouplist = UserUtil::getGroups(array(), array('name' => 'ASC'));
     foreach ($grouplist as $k => $v) {
         $id = $v['gid'];
         $disp = $v['name'];
         if (strpos($excludeList, ",{$id},") === false) {
             $data[$id] = $disp;
         }
     }
     return self::getSelector_Generic($name, $data, $selectedValue, $defaultValue, $defaultText, $allValue, $allText, $submit, $disabled, $multipleSize);
 }
Beispiel #5
0
 /**
  * Simplify "in" & "out" file information. 
  *   
  * > The purpose is optimize insertion and deletion actions.\n
  * > For example, if file indicates that a user must be deleted from a group
  * > and added in the same group id, group id will be removed from "in" and "out" list.\n
  * > Filter non existent group ids. Aviod redundant information processing
  * 
  * @parameter array $args.
  * Array description:
  * * integer **uid** User id
  * * string **in** Group ids separated by "|". Group ids where user will be added.
  * * string **out** Group ids separated by "|". Group ids where user will be removed.
  * 
  * @return array 
  */
 public function optimizeGroups($args){
     $this->throwForbiddenUnless(SecurityUtil::checkPermission('IWusers::', '::', ACCESS_READ));
     $line = $args['data'];
     //Initialize vars
     $result = array();
     $result['in'] = null;
     $result['out'] = null;
             
     // All Zikula groups
     $allGroups = array_keys(UserUtil::getGroups());
     // User groups
     $usrGroups = UserUtil::getGroupsForUser($args['uid']); 
    
     if (array_key_exists('in', $line)) {
         // File contains "in" field
         // 1. Erase non exitent groups
         $clean_in = array_intersect($allGroups, explode('|', $line['in']));
         // 2. Mantain only new groups. Remove gid from list "in" if user already belongs to this group            
         $result['in'] = implode('|', array_diff($clean_in, $usrGroups));             
     } else {
         // Needed in "out" clean process
         $clean_in = array();
     }        
     if (array_key_exists('out', $line)) {
         // File contains "out" field
         $out = explode('|', $line['out']);
         // 1. Erase non exitent groups
         $clean_out = array_intersect($allGroups, explode('|', $line['out']));
         // 2. Only in "out" list gid that are not in "in" list
         $out = array_diff($clean_out, $clean_in);
         // 3. Only in "out" list gids where user is member
         $result['out'] = implode('|', array_intersect($out, $usrGroups));            
     }                
     return $result;
 }
Beispiel #6
0
/**
     * Funció: getAllGroups
     *         Retorna tots els grups de zikula
     * @author: Joan Guillén i Pelegay(jguille2@xtec.cat)
     * @param: 
     * @return: Array amb tota la taula groups
     */
    public function getAllGroupsUnits() {
        //Verificar permisos
       $this->throwForbiddenUnless(SecurityUtil::checkPermission('Cataleg::', '::', ACCESS_READ));
      /* $grupsUnitatsLlista = ModUtil::getVar("Cataleg", "grupsUnitats");
       //$allGroups = DBUtil::selectObjectArray('groups', '','','-1','-1','gid');
       $allGroups = UserUtil::getGroups();
       foreach ($grupsUnitatsLlista as $grup) {
           $allGroupsUnits[$grup] = $allGroups[$grup];
       }*/
       $allGroups = UserUtil::getGroups('','name');
       $grupsUnitatsLlista = ModUtil::getVar("Cataleg", "grupsUnitats");
       foreach ($allGroups as $gid=>$group){
           if (in_array($gid,$grupsUnitatsLlista)) {
               $allGroupsUnits[$gid] = $group;
           }
       }
       return $allGroupsUnits;
    }