From 69b46857922681dd612d78a65edbe625e47d605c Mon Sep 17 00:00:00 2001 From: =?utf8?q?St=C3=A9phane=20Jacob?= Date: Sat, 20 Feb 2010 01:48:49 +0100 Subject: [PATCH 1/1] Moves getXorgId and getSchoolId to Profile. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Stéphane Jacob --- classes/profile.php | 42 ++++++++++++++++++++++++++++++++++++++++++ include/user.func.inc.php | 22 ---------------------- include/vcard.inc.php | 2 -- modules/admin.php | 14 +------------- modules/lists.php | 2 +- modules/marketing.php | 3 +-- modules/profile.php | 2 -- modules/xnetgrp.php | 2 +- 8 files changed, 46 insertions(+), 43 deletions(-) diff --git a/classes/profile.php b/classes/profile.php index ad80d8a..f1dc23d 100644 --- a/classes/profile.php +++ b/classes/profile.php @@ -607,8 +607,50 @@ class Profile $first = 0; } } + } + + /** The school identifier consists of 6 digits. The first 3 represent the + * promotion entry year. The last 3 indicate the student's rank. + * + * Our identifier consists of 8 digits and both half have the same role. + * This enables us to deal with bigger promotions and with a wider range + * of promotions. + * + * getSchoolId returns a school identifier given one of ours. + * getXorgId returns a X.org identifier given a school identifier. + */ + public static function getSchoolId($xorgId) + { + if (!preg_match('/^[0-9]{8}$/', $xorgId)) { + return null; + } + + $year = intval(substr($xorgId, 0, 4)); + $rank = intval(substr($xorgId, 5, 3)); + if ($year < 1996) { + return null; + } elseif ($year < 2000) { + $year = intval(substr(1900 - $year, 1, 3)); + return sprintf('%02u0%03u', $year, $rank); + } else { + $year = intval(substr(1900 - $year, 1, 3)); + return sprintf('%03u%03u', $year, $rank); + } + } + public static function getXorgId($schoolId) + { + $year = intval(substr($schoolId, 0, 3)); + $rank = intval(substr($schoolId, 3, 3)); + if ($year > 200) { + $year /= 10; + } + if ($year < 96) { + return null; + } else { + return sprintf('%04u%04u', 1900 + $year, $rank); + } } } diff --git a/include/user.func.inc.php b/include/user.func.inc.php index ef0e133..33869a6 100644 --- a/include/user.func.inc.php +++ b/include/user.func.inc.php @@ -84,28 +84,6 @@ function user_clear_all_subs($user_id, $really_del=true) } // }}} -// {{{ 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: diff --git a/include/vcard.inc.php b/include/vcard.inc.php index ecf6d2a..9026171 100644 --- a/include/vcard.inc.php +++ b/include/vcard.inc.php @@ -19,8 +19,6 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * ***************************************************************************/ -require_once('user.func.inc.php'); - class VCard extends PlVCard { private $profile_list = array(); diff --git a/modules/admin.php b/modules/admin.php index f5ec942..b364b3b 100644 --- a/modules/admin.php +++ b/modules/admin.php @@ -653,18 +653,6 @@ class AdminModule extends PLModule return null; } - private static function getMatricule($mat) - { - $year = intval(substr($mat, 0, 3)); - $rang = intval(substr($mat, 3, 3)); - if ($year > 200) { $year /= 10; }; - if ($year < 96) { - return null; - } else { - return sprintf('%04u%04u', 1900+$year, $rang); - } - } - private static function formatNewUser($infosLine, $separator, $promo, $size) { $infos = explode($separator, $infosLine); @@ -753,7 +741,7 @@ class AdminModule extends PLModule && ($sex = self::formatSex($page, $infos[3], $line))) { $name = $infos[1] . ' ' . $infos[0]; $birthDate = self::formatBirthDate($infos[2]); - $xorgId = self::getMatricule($infos[4]); + $xorgId = Profile::getXorgId($infos[4]); XDB::execute('INSERT INTO profiles (hrpid, xorg_id, ax_id, birthdate_ref, sex) VALUES ({?}, {?}, {?}, {?})', diff --git a/modules/lists.php b/modules/lists.php index 3313bea..cce4dd2 100644 --- a/modules/lists.php +++ b/modules/lists.php @@ -579,9 +579,9 @@ class ListsModule extends PLModule static public function no_login_callback($login) { - require_once 'user.func.inc.php'; global $list_unregistered, $globals; + /* TODO: fixes this call to a removed function. */ $users = get_not_registered_user($login, true); if ($users && $users->total()) { if (!isset($list_unregistered)) { diff --git a/modules/marketing.php b/modules/marketing.php index eecab75..fc4a95f 100644 --- a/modules/marketing.php +++ b/modules/marketing.php @@ -64,8 +64,7 @@ class MarketingModule extends PLModule } $matricule = $user->profile()->xorg_id; - require_once('user.func.inc.php'); - $matricule_X = get_X_mat($matricule); + $matricule_X = Profile::getSchoolId($matricule); $page->assign('full_name', $user->fullName()); $page->assign('promo', $user->promo()); diff --git a/modules/profile.php b/modules/profile.php index 62e44d8..da3b414 100644 --- a/modules/profile.php +++ b/modules/profile.php @@ -228,7 +228,6 @@ class ProfileModule extends PLModule // Now that we know this is the profile of an existing user, we can // switch to the appropriate template. $page->changeTpl('profile/profile.tpl', SIMPLE); - require_once 'user.func.inc.php'; // Determines the access level at which the profile will be displayed. if (!S::logged() || Env::v('view') == 'public') { @@ -586,7 +585,6 @@ class ProfileModule extends PLModule function handler_referent(&$page, $user) { - require_once 'user.func.inc.php'; $page->changeTpl('profile/fiche_referent.tpl', SIMPLE); $user = Profile::get($user); diff --git a/modules/xnetgrp.php b/modules/xnetgrp.php index c669cb4..de108fc 100644 --- a/modules/xnetgrp.php +++ b/modules/xnetgrp.php @@ -794,7 +794,6 @@ class XnetGrpModule extends PLModule private function changeLogin(PlPage &$page, PlUser &$user, MMList &$mmlist, $login) { - require_once 'user.func.inc.php'; // Search the uid of the user... $res = XDB::query("SELECT f.id, f.alias FROM aliases AS a @@ -802,6 +801,7 @@ class XnetGrpModule extends PLModule WHERE a.alias = {?}", $login); if ($res->numRows() == 0) { + // TODO: replace this call to a removed function. $x = get_not_registered_user($login); if (!$x) { $page->trigError("Le login $login ne correspond à aucun X."); -- 2.1.4