Moving to GitHub.
[platal.git] / bin / marketPromo.php
index 036449e..076e019 100755 (executable)
@@ -2,12 +2,12 @@
 <?php
 
 ini_set('include_path', '.:../include:/usr/share/php');
-require_once('connect.db.inc.php');
-require_once('marketing.inc.php');
+require_once 'connect.db.inc.php';
+require_once 'marketing.inc.php';
 
 $opts = getopt('f:l:m:');
-if (($opts['f'] && $opts['f'] == '-') || empty($opts['f'])) { 
-    $file = 'php://stdin'; 
+if (($opts['f'] && $opts['f'] == '-') || empty($opts['f'])) {
+    $file = 'php://stdin';
 } else {
     $file = $opts['f'];
 }
@@ -19,24 +19,26 @@ $logcol = intval($opts['l']);
 $handle = fopen($file, 'r');
 
 while ($data = fgetcsv($handle)) {
-    $login = $data[$logcol];
-    $matri = preg_replace('/1(\d{2})(\d{3})/', '20${1}0\2', $data[$matcol]);
-    if (!is_numeric($matri)) {
-        echo "ERROR The matricule ($matri) is not a numerical value\n";
+    $login  = $data[$logcol];
+    $xorgid = preg_replace('/1(\d{2})(\d{3})/', '20${1}0\2', $data[$matcol]);
+    if (!is_numeric($xorgid)) {
+        echo "ERROR The matricule ($xorgid) is not a numerical value.\n";
         break;
     }
-    $query = XDB::query("SELECT  user_id
-                           FROM  auth_user_md5
-                          WHERE  matricule = {?}",
-                        $matri);
+    $query = XDB::query("SELECT  a.uid
+                           FROM  profiles         AS p
+                     INNER JOIN  account_profiles AS ap ON (p.pid = ap.pid AND FIND_IN_SET('owner', perms)
+                     INNER JOIN  accounts         AS a  ON (a.uid = ap.uid)
+                          WHERE  p.xorg_id = {?}",
+                        $xorgid);
     $uid = $query->fetchOneCell();
     if (!$uid) {
-        echo "WARNING Can't find uid for matricule $matri (login $login)\n";
+        echo "WARNING Can't find uid for matricule $xorgid (login $login)\n";
         continue;
     }
     $market = Marketing::get($uid, "$login@poly.polytechnique.fr");
     if (!is_null($market)) {
-        echo "WARNING A marketing has already been to $matri on $login\n";
+        echo "WARNING A marketing has already been to $xorgid on $login\n";
         continue;
     }
     $market = new Marketing($uid, "$login@poly.polytechnique.fr", 'default', null, 'staff');
@@ -44,6 +46,6 @@ while ($data = fgetcsv($handle)) {
     $market->send();
 }
 
-// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
+// vim:set et sw=4 sts=4 sws=4 foldmethod=marker fenc=utf-8:
 ?>