Here is the second step. It is the form to mass change sections of
notes. I think that moving Nuno's script to the server is not necessary.
It can be easily run locally and through the web interface only changes
can be done.

> Then do a select on the notes db and check for non-valid IDs and do a
> foreach{} to print a html form to allow us to change the IDs.

The interface should be more universal to allow changes of notes in e.g.
split sections.

Jakub Vrana
Index: user-notes.php
===================================================================
RCS file: /repository/php-master-web/manage/user-notes.php,v
retrieving revision 1.39
diff -u -r1.39 user-notes.php
--- user-notes.php      26 May 2004 10:15:09 -0000      1.39
+++ user-notes.php      28 May 2004 15:42:39 -0000
@@ -152,6 +152,8 @@
  </tr>
 </table>
 </form>
+
+<p><a href="<?php echo $PHP_SELF;?>?action=mass">Mass change of sections</a></p>
 <?php
 foot();
 exit;
@@ -171,6 +173,79 @@
   or die("unable to select database");
 
 switch($action) {
+case 'mass':
+  head();
+  $where = array();
+  if ($old_sect)
+    $where[] = "sect = '$old_sect'";
+  if ($ids)
+    $where[] = "id IN ($ids)";
+  
+  if ($step == 2) {
+    if (!mysql_query("UPDATE note SET sect = '$new_sect' WHERE " . implode(" AND ", 
$where)))
+      echo "<p>Mass change failed: " . mysql_error() . "</p>\n";
+    else
+      echo "<p>Mass change succeeded.</p>\n";
+  } elseif ($step == 1) {
+    if ($new_sect && ($ids || $old_sect)) {
+      if (!($result = mysql_query("SELECT COUNT(*) FROM note WHERE " . implode(" AND 
", $where))))
+        echo "<p>SQL error: " . mysql_error() . "</p>\n";
+      elseif (!($count = mysql_result($result, 0, 0)))
+        echo "<p>There are no such notes.</p>\n";
+      else {
+        $step = 2;
+        $msg = "Are you sure to change section of <b>$count note(s)</b>";
+        $msg .= ($ids ? " with IDs <b>$ids</b>" : "");
+        $msg .= ($old_sect ? " from section <b>$old_sect</b>" : "");
+        $msg .= " to section <b>$new_sect</b>?";
+        echo "<p>$msg</p>\n";
+?>
+<form action="<?php echo $PHP_SELF; ?>?action=mass" method="post">
+<input type="hidden" name="step" value="2">
+<input type="hidden" name="old_sect" value="<?php echo $old_sect; ?>">
+<input type="hidden" name="ids" value="<?php echo $ids; ?>">
+<input type="hidden" name="new_sect" value="<?php echo $new_sect; ?>">
+<input type="submit" value="Change">
+</form>
+<?php
+      }
+    } else {
+      if (!$new_sect)
+        echo "<p><b>You have to fill-in new section.</b></p>\n";
+      if (!$ids && !$old_sect)
+        echo "<p><b>You have to fill-in curent section or notes IDs (or 
both).</b></p>\n";
+    }
+  }
+  if ($step < 2) {
+?>
+<form action="<?php echo $PHP_SELF; ?>?action=mass" method="post">
+<input type="hidden" name="step" value="1">
+<p>Change section of notes which fit these criteria:</p>
+<table>
+ <tr>
+  <th align="right">Current section:</th>
+  <td><input type="text" name="old_sect" value="<?php echo $old_sect; ?>" size="30" 
maxlength="80" /> (filename without extension)</td>
+ </tr>
+ <tr>
+  <th align="right">Notes IDs:</th>
+  <td><input type="text" name="ids" value="<?php echo $ids; ?>" size="30" 
maxlength="80" /> (comma separated list)</td>
+ </tr>
+ <tr>
+  <th align="right">Move to section:</th>
+  <td><input type="text" name="new_sect" value="<?php echo $new_sect; ?>" size="30" 
maxlength="80" /></td>
+ </tr>
+ <tr> 
+  <td align="center" colspan="2">
+    <input type="submit" value="Change" />
+  </td>
+ </tr>
+</table>
+</form>
+<?php
+  }
+  echo "<p><a href='$PHP_SELF'>Back to notes index</a></p>\n";
+  foot();
+  exit;
 case 'approve':
   if ($id) {
     if ($result = mysql_query("SELECT * FROM note WHERE id=$id")) {

Reply via email to