Exemplo n.º 1
0
 public function createUser($params, $userdata)
 {
     if (defined("_API_DEBUG") && _API_DEBUG) {
         file_put_contents('create_user.txt', "\n\n----------------\n\n" . print_r($params, true) . " || " . print_r($userdata, true), FILE_APPEND);
     }
     $set_idst = isset($params['idst']) ? $params['idst'] : false;
     //fix grifomultimedia soap	argument [auth a.b.]
     $userdata = !isset($userdata['userid']) && isset($params) ? $params : $userdata;
     if (!isset($userdata['userid'])) {
         return false;
     }
     $id_user = $this->aclManager->registerUser($userdata['userid'], isset($userdata['firstname']) ? $userdata['firstname'] : '', isset($userdata['lastname']) ? $userdata['lastname'] : '', isset($userdata['password']) ? $userdata['password'] : '', isset($userdata['email']) ? $userdata['email'] : '', '', isset($userdata['signature']) ? $userdata['signature'] : '', false, $set_idst, isset($userdata['pwd_expire_at']) ? $userdata['pwd_expire_at'] : '');
     // suspend
     if (isset($userdata['valid']) && $userdata['valid'] == '0') {
         $res = $this->aclManager->suspendUser($id_user);
     }
     // registration code:
     if ($id_user && !empty($userdata['reg_code']) && !empty($userdata['reg_code_type'])) {
         require_once _base_ . '/lib/lib.usermanager.php';
         $user_manager = new UserManager();
         $uma = new UsermanagementAdm();
         $reg_code_res = $user_manager->_render->processRegistrationCode($this->aclManager, $uma, $id_user, $userdata['reg_code'], $userdata['reg_code_type']);
         if ($reg_code_res['success'] == false) {
             $this->aclManager->deleteUser($id_user);
             $output = array('success' => false, 'message' => 'Registration Code Error: ' . $reg_code_res['msg']);
             $id_user = false;
             return $output;
         }
     }
     if (!$id_user) {
         if (defined("_API_DEBUG") && _API_DEBUG) {
             file_put_contents('create_user.txt', "?!: " . var_export($id_user, true), FILE_APPEND);
         }
         return false;
     }
     if ($id_user) {
         if (!isset($userdata['role'])) {
             $level = ADMIN_GROUP_USER;
         } else {
             switch ($userdata['role']) {
                 case 'godadmin':
                     $level = ADMIN_GROUP_GODADMIN;
                     break;
                 case 'admin':
                     $level = ADMIN_GROUP_ADMIN;
                     break;
                 case 'pubadmin':
                     $level = ADMIN_GROUP_PUBLICADMIN;
                     break;
                 default:
                     $level = ADMIN_GROUP_USER;
                     break;
             }
         }
         //subscribe to std groups
         $group = $this->aclManager->getGroupST($level);
         //'/framework/level/user');
         $this->aclManager->addToGroup($group, $id_user);
         $group = $this->aclManager->getGroupST('/oc_0');
         $this->aclManager->addToGroup($group, $id_user);
         $group = $this->aclManager->getGroupST('/ocd_0');
         $this->aclManager->addToGroup($group, $id_user);
         if (isset($userdata['language'])) {
             require_once _base_ . '/lib/lib.preference.php';
             $user_pref = new UserPreferences($id_user);
             $user_pref->setLanguage($userdata['language']);
         }
         //check if some additional fields have been set
         $okcustom = true;
         if (isset($userdata['_customfields'])) {
             require_once _adm_ . '/lib/lib.field.php';
             $fields =& $userdata['_customfields'];
             if (count($fields) > 0) {
                 $fl = new FieldList();
                 $okcustom = $fl->storeDirectFieldsForUser($id_user, $fields);
             }
         }
         $entities = array();
         if (isset($userdata['orgchart'])) {
             $branches = explode(";", $userdata['orgchart']);
             if (is_array($branches)) {
                 foreach ($branches as $branch) {
                     $idOrg = $this->_getBranch($branch);
                     if ($idOrg !== false) {
                         $oc = $this->aclManager->getGroupST('/oc_' . $idOrg);
                         $ocd = $this->aclManager->getGroupST('/ocd_' . $idOrg);
                         $this->aclManager->addToGroup($oc, $id_user);
                         $this->aclManager->addToGroup($ocd, $id_user);
                         $entities[$oc] = $oc;
                         $entities[$ocd] = $ocd;
                     }
                 }
             }
         }
         $enrollrules = new EnrollrulesAlms();
         $enrollrules->newRules('_NEW_USER', array($id_user), $userdata['language'], 0, !empty($entities) ? $entities : false);
         // save external user data:
         if ($params['ext_not_found'] && !empty($params['ext_user']) && !empty($params['ext_user_type'])) {
             $pref_path = 'ext.user.' . $params['ext_user_type'];
             $pref_val = 'ext_user_' . $params['ext_user_type'] . "_" . (int) $params['ext_user'];
             $pref = new UserPreferencesDb();
             $pref->assignUserValue($id_user, $pref_path, $pref_val);
             if (defined("_API_DEBUG") && _API_DEBUG) {
                 file_put_contents('create_user.txt', print_r($id_user, true) . " || " . print_r($pref_path, true) . " || " . print_r($pref_val, true), FILE_APPEND);
             }
         } else {
             if (defined("_API_DEBUG") && _API_DEBUG) {
                 file_put_contents('create_user.txt', "??: \n\n" . print_r($params, true), FILE_APPEND);
             }
         }
     }
     return $id_user;
 }