Fixes #811: Improve interface to add medal ranks and avoid losing data
authorOlivier Le Floch <olivier.le-floch@polytechnique.org>
Fri, 6 Jun 2008 00:59:22 +0000 (02:59 +0200)
committerOlivier Le Floch <olivier.le-floch@polytechnique.org>
Fri, 6 Jun 2008 00:59:22 +0000 (02:59 +0200)
ChangeLog
modules/profile.php
templates/profile/admin_decos.tpl

index 2296f85..6a26ba4 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -10,6 +10,10 @@ New:
         - Add a 'disallow all' robots.txt in development working copies.   -VZA
 
 Bug/Wish:
+
+    * Admin:
+        - #811: Improve interface to add medal ranks and avoid losing data -ALK
+
     * Core:
         - Fix email sending, correcting bugs introduced in r1897           -VZA
         - #841: Improves contrast of links in legends in skin 'Espace'     -FRU
index bef05a8..467f11e 100644 (file)
@@ -791,15 +791,24 @@ class ProfileModule extends PLModule
             if (Post::v('act') == 'del') {
                 XDB::execute('DELETE FROM  profile_medals_grades
                                     WHERE  mid={?} AND gid={?}', $mid, Post::i('gid'));
-            } elseif (Post::v('act') == 'new') {
-                XDB::execute('INSERT INTO  profile_medals_grades (mid,gid)
-                                   VALUES  ({?},{?})',
-                        $mid, max(array_keys(Post::v('grades', array(0))))+1);
             } else {
                 foreach (Post::v('grades', array()) as $gid=>$text) {
-                    XDB::execute('UPDATE  profile_medals_grades
-                                     SET  pos={?}, text={?}
-                                   WHERE  gid={?} AND mid={?}', $_POST['pos'][$gid], $text, $gid, $mid);
+                    if ($gid === 0) {
+                        if (!empty($text)) {
+                            $res = XDB::query('SELECT  MAX(gid)
+                                                 FROM  profile_medals_grades
+                                                WHERE  mid = {?}', $mid);
+                            $gid = $res->fetchOneCell() + 1;
+
+                            XDB::execute('INSERT INTO  profile_medals_grades (mid, gid, text, pos)
+                                               VALUES  ({?}, {?}, {?}, {?})',
+                                $mid, $gid, $text, $_POST['pos']['0']);
+                        }
+                    } else {
+                        XDB::execute('UPDATE  profile_medals_grades
+                                         SET  pos={?}, text={?}
+                                       WHERE  gid={?} AND mid={?}', $_POST['pos'][$gid], $text, $gid, $mid);
+                    }
                 }
             }
             $res = XDB::iterator('SELECT gid, text, pos FROM profile_medals_grades WHERE mid={?} ORDER BY pos', $mid);
index 722ebd8..fe8e526 100644 (file)
 {literal}
 <script type="text/javascript">
   <!--
-  function new_grade() {
-    document.forms.form_grade.act.value = "new";
-    document.forms.form_grade.submit();
-    return true;
-  }
-
   function del_grade( myid ) {
     if (confirm ("You are about to delete this entry. Do you want to proceed?")) {
       document.forms.form_grade.act.value = "del";
       <th>ordre</th>
       <th>&nbsp;</th>
     </tr>
-    <tr>
-      <td colspan='3'>
-        Nouveau ...
-      </td>
-      <td  class='action'>
-        <a href='javascript:new_grade()'>nouveau{icon name=add title='nouveau grade'}</a>
-      </td>
-    </tr>
     {iterate from=$grades item=g}
     <tr class="{cycle values="pair,impair"}">
       <td>{$g.gid}</td>
     </tr>
     {/iterate}
     <tr class="{cycle values="impair,pair"}">
+      <td></td>
+      <td>
+        <input type='text' size='65' name="grades[0]" />
+      </td>
+      <td>
+        <input type='text' maxlength='2' name="pos[0]" value="0" />
+      </td>
+      <td class='action'>
+        <a href='javascript:document.forms.form_grade.submit()'>{icon name=add title='nouveau grade'}</a>
+      </td>
+    </tr>
+    <tr class="{cycle values="impair,pair"}">
       <td colspan='4' class="center">
         <input type='hidden' name='frm_id' value='{$smarty.post.frm_id}' />
         <input type='hidden' name='action' value='{$smarty.post.action}' />
         <input type='hidden' name='act' value='' />
         <input type='hidden' name='gid' value='' />
-        <input type='submit' name='gr_sub' value='Sauver' />
+        <input type='submit' name='gr_sub' value='Enregistrer' />
       </td>
     </tr>
   </table>