Fix many uid fields in profile tables created by newdirectory.
[platal.git] / modules / profile / decos.inc.php
index de68fd6..7a88b61 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /***************************************************************************
- *  Copyright (C) 2003-2007 Polytechnique.org                              *
+ *  Copyright (C) 2003-2010 Polytechnique.org                              *
  *  http://opensource.polytechnique.org/                                   *
  *                                                                         *
  *  This program is free software; you can redistribute it and/or modify   *
@@ -27,10 +27,10 @@ class ProfileDeco implements ProfileSetting
         if (is_null($value)) {
             // Fetch already attributed medals
             $res = XDB::iterRow("SELECT  m.id AS id, s.gid AS grade
-                                   FROM  profile_medals_sub    AS s
-                             INNER JOIN  profile_medals        AS m ON ( s.mid = m.id )
+                                   FROM  profile_medals    AS s
+                             INNER JOIN  profile_medal_enum        AS m ON ( s.mid = m.id )
                                   WHERE  s.uid = {?}",
-                                S::i('uid'));
+                                $page->pid());
             $value = array();
             while (list($id, $grade) = $res->next()) {
                 $value[$id] = array('grade' => $grade,
@@ -61,9 +61,9 @@ class ProfileDeco implements ProfileSetting
         foreach ($orig as $id=>&$val) {
             if (!isset($value[$id]) || $val['grade'] != $value[$id]['grade']) {
                 if ($val['valid']) {
-                    XDB::execute("DELETE FROM  profile_medals_sub
+                    XDB::execute("DELETE FROM  profile_medals
                                         WHERE  uid = {?} AND mid = {?}",
-                                 S::i('uid'), $id);
+                                 $page->pid(), $id);
                 } else {
                     $req = MedalReq::get_request(S::i('uid'), $id);
                     if ($req) {
@@ -76,8 +76,9 @@ class ProfileDeco implements ProfileSetting
         // Add new ones
         foreach ($value as $id=>&$val) {
             if (!isset($orig[$id]) || $orig[$id]['grade'] != $val['grade']) {
-                $req = new MedalReq(S::i('uid'), $id, $val['grade']);
+                $req = new MedalReq(S::user(), $id, $val['grade']);
                 $req->submit();
+                sleep(1);
             }
         }
     }
@@ -97,27 +98,27 @@ class ProfileDecos extends ProfilePage
 
     protected function _fetchData()
     {
-        $res = XDB::query("SELECT  profile_medals_pub
-                             FROM  auth_user_quick
-                            WHERE  user_id = {?}",
-                          S::i('uid'));
+        $res = XDB::query("SELECT  medals_pub
+                             FROM  profiles
+                            WHERE  pid = {?}",
+                          $this->pid());
         $this->values['medals_pub'] = $res->fetchOneCell();
     }
 
     protected function _saveData()
     {
         if ($this->changed['medals_pub']) {
-            XDB::execute("UPDATE  auth_user_quick
-                             SET  profile_medals_pub = {?}
-                           WHERE  user_id = {?}",
-                         $this->values['medals_pub'], S::i('uid'));
+            XDB::execute("UPDATE  profiles
+                             SET  medals_pub = {?}
+                           WHERE  pid = {?}",
+                         $this->values['medals_pub'], $this->pid());
         }
     }
 
-    public function _prepare(PlatalPage &$page, $id)
+    public function _prepare(PlPage &$page, $id)
     {
         $res    = XDB::iterator("SELECT  *, FIND_IN_SET('validation', flags) AS validate
-                                   FROM  profile_medals
+                                   FROM  profile_medal_enum
                                ORDER BY  type, text");
         $mlist  = array();
         while ($tmp = $res->next()) {