+// {{{ function set_new_usage()
+
+function set_new_usage($uid, $usage, $alias=false)
+{
+ XDB::execute("UPDATE auth_user_md5 set nom_usage={?} WHERE user_id={?}",$usage ,$uid);
+ XDB::execute("DELETE FROM aliases WHERE FIND_IN_SET('usage',flags) AND id={?}", $uid);
+ if ($alias && $usage) {
+ XDB::execute("UPDATE aliases SET flags=flags & 255-1 WHERE id={?}", $uid);
+ XDB::execute("INSERT INTO aliases VALUES({?}, 'alias', 'usage,bestalias', {?}, null)",
+ $alias, $uid);
+ }
+ $r = XDB::query("SELECT alias FROM aliases WHERE FIND_IN_SET('bestalias', flags) AND id = {?}", $uid);
+ if ($r->numRows() == "") {
+ XDB::execute("UPDATE aliases SET flags = 1 | flags WHERE id = {?} LIMIT 1", $uid);
+ $r = XDB::query("SELECT alias FROM aliases WHERE FIND_IN_SET('bestalias', flags) AND id = {?}", $uid);
+ }
+ user_reindex($uid);
+ return $r->fetchOneCell();
+}
+
+// }}}
+// {{{ function get_X_mat
+function get_X_mat($ourmat)
+{
+ if (!preg_match('/^[0-9]{8}$/', $ourmat)) {
+ // le matricule de notre base doit comporter 8 chiffres
+ return 0;
+ }
+
+ $year = intval(substr($ourmat, 0, 4));
+ $rang = intval(substr($ourmat, 5, 3));
+ if ($year < 1996) {
+ return;
+ } elseif ($year < 2000) {
+ $year = intval(substr(1900 - $year, 1, 3));
+ return sprintf('%02u0%03u', $year, $rang);
+ } else {
+ $year = intval(substr(1900 - $year, 1, 3));
+ return sprintf('%03u%03u', $year, $rang);
+ }
+}
+
+// }}}
+
+
+// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: