@@ -94,6 +94,7 @@ function getAuthenticationInfo()
9494 global $ dbi , $ globalZone ;
9595
9696 $ dbi ->join (_USER_TYPES_ . " t " , "t.typeID=u.userType " , "INNER " );
97+ $ dbi ->join (_SUBELER_ . " s " , "s.subeID=u.ySubeKodu " , "LEFT " );
9798
9899 if ($ this ->authDbStdSsnSetting == "on " )
99100 {
@@ -118,7 +119,10 @@ function getAuthenticationInfo()
118119
119120 $ dbi ->where ("u.active " , "1 " );
120121 $ dbi ->where ("t.loginType " , $ this ->authLoginTypes , "IN " );
121- $ authenticationInfo = $ dbi ->getOne (_USERS_ . " u " , "u.aid, u.pwd, u.email, u.picture, u.name, u.lastName, u.ySubeKodu, u.campusID, u.userType, u.expireDate, u.firebaseId, u.firebaseToken, u.pwdPlain, u.id, t.loginType " );
122+ $ authenticationInfo = $ dbi ->getOne (_USERS_ . " u " , "u.aid, u.pwd, u.email, u.picture, u.name, u.lastName, u.ySubeKodu, s.subeID, s.stype, u.userType, u.expireDate, u.firebaseId, u.firebaseToken, u.pwdPlain, u.id, t.loginType " );
123+
124+ //make school id 0 if it is null for hq
125+ if (is_null ($ authenticationInfo ["ySubeKodu " ])) $ authenticationInfo ["ySubeKodu " ] = "0 " ;
122126
123127 //check picture
124128 if (empty ($ authenticationInfo ["picture " ])) $ authenticationInfo ["picture " ] = "https://schst.in/nopicture " ;
@@ -155,18 +159,45 @@ function getAuthenticationInfo()
155159
156160 if (empty ($ getLmsUser ["users " ][0 ]))
157161 {
158-
159- $ users = array (
160- 'username ' => $ authenticationInfo ["aid " ],
161- 'password ' => $ authenticationInfo ["pwdPlain " ],
162- 'firstname ' => $ authenticationInfo ["name " ],
163- 'lastname ' => $ authenticationInfo ["lastName " ],
164- 'email ' => $ authenticationInfo ["email " ],
165- 'studentno ' => $ this ->createStudentNo ($ authenticationInfo ["id " ]),
166- 'auth ' => 'lti '
167- );
168-
169- $ createLMSUser = $ this ->lmsCreateUsers ($ users );
162+ if ($ authenticationInfo ["ySubeKodu " ] == "0 " || $ authenticationInfo ["stype " ] == "campus " )
163+ {
164+ $ insKeys = array ();
165+
166+ $ moodleInsKey = $ dbi ->get (_MOODLE_CONFIG_ , null , "moodleInsKey " );
167+ foreach ($ moodleInsKey as $ moodleKey )
168+ {
169+ $ insKeys [] = array ('institutionkey ' => $ moodleKey ["moodleInsKey " ]);
170+ }
171+
172+ $ users = array (
173+ 'username ' => $ authenticationInfo ["aid " ],
174+ 'password ' => $ authenticationInfo ["pwdPlain " ],
175+ 'firstname ' => $ authenticationInfo ["name " ],
176+ 'lastname ' => $ authenticationInfo ["lastName " ],
177+ 'email ' => $ authenticationInfo ["email " ],
178+ 'auth ' => 'lti '
179+ );
180+
181+ $ createLMSUser = $ this ->lmsCreateManagerUsers ($ insKeys , $ users );
182+
183+ }
184+ else
185+ {
186+ $ users = array (
187+ 'username ' => $ authenticationInfo ["aid " ],
188+ 'password ' => $ authenticationInfo ["pwdPlain " ],
189+ 'firstname ' => $ authenticationInfo ["name " ],
190+ 'lastname ' => $ authenticationInfo ["lastName " ],
191+ 'email ' => $ authenticationInfo ["email " ],
192+ 'auth ' => 'lti '
193+ );
194+
195+ //If User Type is Student
196+ if ($ authenticationInfo ["userType " ] == "8 " ) $ users ["studentno " ] = $ this ->createStudentNo ($ authenticationInfo ["id " ]);
197+
198+ $ createLMSUser = $ this ->lmsCreateUsers ($ users );
199+
200+ }
170201
171202 if (!empty ($ createLMSUser ))
172203 {
@@ -176,7 +207,21 @@ function getAuthenticationInfo()
176207 $ dbi ->where ("id " , $ authenticationInfo ["id " ]);
177208 $ update = $ dbi ->update (_USERS_ , $ queryData );
178209 }
210+ }
211+ else
212+ {
213+ $ dbi ->where ("aid " , $ authenticationInfo ["aid " ]);
214+ $ dbi ->where ("id " , $ authenticationInfo ["id " ]);
215+ $ getLmsUserId = $ dbi ->getValue (_USERS_ , "lmsUserId " );
179216
217+ if (empty ($ getLmsUserId ))
218+ {
219+ $ queryData = array ('lmsUserId ' => $ getLmsUser ["users " ][0 ]["id " ]);
220+
221+ $ dbi ->where ("aid " , $ authenticationInfo ["aid " ]);
222+ $ dbi ->where ("id " , $ authenticationInfo ["id " ]);
223+ $ update = $ dbi ->update (_USERS_ , $ queryData );
224+ }
180225 }
181226
182227 }
0 commit comments