ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilOpenIdAttributeToUser.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 include_once './Services/OpenId/classes/class.ilOpenIdSettings.php';
5 
14 {
15  private $settings = null;
16  private $writer = null;
17 
21  public function __construct()
22  {
23  global $ilLog;
24 
25  $this->log = $ilLog;
26 
27  $this->settings = ilOpenIdSettings::getInstance();
28 
29  include_once('./Services/Xml/classes/class.ilXmlWriter.php');
30  $this->writer = new ilXmlWriter();
31 
32  }
33 
41  public function create($a_username,$a_userdata = array())
42  {
43  $a_userdata = $this->parseFullname($a_userdata);
44 
45  $this->writer->xmlStartTag('Users');
46 
47  // Single users
48  // Required fields
49  // Create user
50  $this->writer->xmlStartTag('User',array('Action' => 'Insert'));
51  $this->writer->xmlElement('Login',array(),$new_name = ilAuthUtils::_generateLogin($a_username));
52 
53  // Assign to role only for new users
54  $this->writer->xmlElement('Role',array('Id' => $this->settings->getDefaultRole(),
55  'Type' => 'Global',
56  'Action' => 'Assign'),'');
57 
58  if(isset($a_userdata['email']))
59  {
60  $this->writer->xmlElement('Email',array(),$a_userdata['email']);
61  }
62  if(isset($a_userdata['postcode']))
63  {
64  $this->writer->xmlElement('PostalCode',array(),$a_userdata['postcode']);
65  }
66  if(isset($a_userdata['dob']) and $a_userdata['dob'])
67  {
68  $this->writer->xmlElement('Birthday',array(),$a_userdata['dob']);
69  }
70  if(isset($a_userdata['gender']))
71  {
72  $this->writer->xmlElement('Gender',array(),strtolower($a_userdata['gender']));
73  }
74  if(isset($a_userdata['title']))
75  {
76  $this->writer->xmlElement('Title',array(),$a_userdata['title']);
77  }
78  if(isset($a_userdata['firstname']))
79  {
80  $this->writer->xmlElement('Firstname',array(),$a_userdata['firstname']);
81  }
82  if(isset($a_userdata['lastname']))
83  {
84  $this->writer->xmlElement('Lastname',array(),$a_userdata['lastname']);
85  }
86 
87  $this->writer->xmlElement('Active',array(),"true");
88  $this->writer->xmlElement('TimeLimitOwner',array(),7);
89  $this->writer->xmlElement('TimeLimitUnlimited',array(),1);
90  $this->writer->xmlElement('TimeLimitFrom',array(),time());
91  $this->writer->xmlElement('TimeLimitUntil',array(),time());
92  $this->writer->xmlElement('AuthMode',array('type' => 'openid'),'openid');
93  $this->writer->xmlElement('ExternalAccount',array(),$a_username);
94 
95  $this->writer->xmlEndTag('User');
96  $this->writer->xmlEndTag('Users');
97  $this->log->write('OpenId: Started creation of user: '.$new_name);
98 
99  include_once './Services/User/classes/class.ilUserImportParser.php';
100  $importParser = new ilUserImportParser();
101  $importParser->setXMLContent($this->writer->xmlDumpMem(false));
102  $importParser->setRoleAssignment(array($this->settings->getDefaultRole() => $this->settings->getDefaultRole()));
103  $importParser->setFolderId(7);
104  $importParser->startParsing();
105 
106  // Assign timezone
107  if(isset($a_userdata['timezone']))
108  {
109  include_once './Services/Calendar/classes/class.ilCalendarUtil.php';
111 
112  if(isset($tzs[$a_userdata['timezone']]))
113  {
114  $usr_id = ilObjUser::_lookupId($new_name);
115  ilObjUser::_writePref($usr_id, 'user_tz', $a_userdata['timezone']);
116  }
117  }
118 
119  return $new_name;
120  }
121 
122  protected function parseFullname($a_userdata)
123  {
124  include_once './Services/User/classes/class.ilFullnameParser.php';
125 
126  $parser = new ilFullnameParser($a_userdata['fullname']);
127 
128  if($parser->getNotParseable())
129  {
130  return $a_userdata;
131  }
132 
133  $a_userdata['firstname'] = $parser->getFirstName();
134  $a_userdata['lastname'] = $parser->getLastName();
135  $a_userdata['title'] = $parser->getTitle();
136 
137  return $a_userdata;
138  }
139 
140 }
141 ?>