public function testApplyTo() { $pattern = new UserPattern('test'); $params = array(); $pattern->applyTo($params); $this->assertEquals(array(),$params); $params = array('login' => 'toto'); $pattern->applyTo($params); $this->assertEquals(array('login' => 'toto'),$params); $pattern->set_attributes(array( 'email' => '*****@*****.**', 'login' => '%firstname%.%lastname%', 'desc' => 'Utilisateur %login% (%email%)' )); $params = array( 'lastname' => 'Backdoor', 'firstname' => 'Benny' ); $pattern->applyTo($params); $this->assertEquals('Backdoor',$params['lastname']); $this->assertEquals('Benny',$params['firstname']); $this->assertEquals('Benny.Backdoor',$params['login']); $this->assertEquals('*****@*****.**',$params['email']); $this->assertEquals('Utilisateur Benny.Backdoor (Benny.Backdoor@test.fr)',$params['desc']); $params = array( 'lastname' => 'Backdoor', 'firstname' => 'Benny', 'login' => 'BennyB' ); $pattern->applyTo($params); $this->assertEquals('BennyB',$params['login']); $this->assertEquals('*****@*****.**',$params['email']); }
} elseif ($action == 'delete') { /////////////////////////////////////////////////////////////////////////////// $userpattern_id = $params['userpattern_id']; if ($pattern = UserPattern::get($userpattern_id)) { $pattern->delete(); $params['userpattern_id'] = 0; } else { $display['msg'] .= display_err_msg($err['msg']); } $display['search'] = dis_userpattern_search_form($params); } elseif ($action == 'apply') { /////////////////////////////////////////////////////////////////////////////// $userpattern_id = $params['userpattern_id']; if ($pattern = UserPattern::get($userpattern_id)) { $attributes = is_array($params['attributes']) ? $params['attributes'] : array(); $pattern->applyTo($attributes); $return = array('attributes' => $attributes); } if (!empty($err['msg'])) $return = array('err' => $err['msg']); echo json_encode($return); exit(); } /////////////////////////////////////////////////////////////////////////////// // Display /////////////////////////////////////////////////////////////////////////////// $display['head'] = display_head($l_userpattern);
/** * Load extra attributes and keywords from $GLOBALS['cgp_user']['user']['field'] and $GLOBALS['cgp_user']['user']['category'] * @access public **/ public static function init() { if (self::$initialized) { return; } self::$initialized = true; $extra_fields = $GLOBALS['cgp_user']['user']['field']; if (is_array($extra_fields)) { foreach ($extra_fields as $fieldname => $properties) { if (!isset(self::$allowed_attributes[$fieldname])) { $type = $properties['type'] == 'text' || $properties['type'] == 'textarea' ? 'string' : $properties['type']; if (!in_array($type, array('boolean', 'date', 'integer', 'password', 'string'))) { $type = 'string'; } self::$allowed_attributes[$fieldname] = array('type' => $type); if ($type == 'string' && !in_array("%{$fieldname}%", self::$allowed_keywords)) { self::$allowed_keywords[] = "%{$fieldname}%"; } } } } $extra_categories = $GLOBALS['cgp_user']['user']['category']; if (is_array($extra_categories)) { foreach ($extra_categories as $fieldname => $properties) { if (!isset(self::$allowed_attributes[$fieldname])) { self::$allowed_attributes[$fieldname] = array('type' => 'category'); //categories can't be used as keywords } } } }
} else if ($action == 'unlink_mobile') { /////////////////////////////////////////////////////////////////////////////// $remove_q = run_query_userobm_mobile_unlink($params); echo "({".$display['json']."})"; exit(); } else if ($action == 'remove_partnership') { /////////////////////////////////////////////////////////////////////////////// $remove_q = run_query_userobm_mobile_remove_partnership($params); echo "({".$display['json']."})"; exit(); } else if ($action == 'profile_quota') { /////////////////////////////////////////////////////////////////////////////// $profile_name = $params['profile_name']; if ($params['user_pattern']) { $pattern = UserPattern::get($params['user_pattern']); if ($pattern->__get('profile') == $profile_name) { $user_pattern_quota = $pattern->__get('mail_quota'); $profile_quota = (!empty($user_pattern_quota)) ? $user_pattern_quota : $params['profiles'][$profile_name]['properties']['mail_quota_default']; } else { $profile_quota = $params['profiles'][$profile_name]['properties']['mail_quota_default']; } } else { $profile_quota = $params['profiles'][$profile_name]['properties']['mail_quota_default']; } echo "({quota:".$profile_quota."})"; exit(); } of_category_user_action_switch($module, $action, $params);