Index: common/db/textblock.php
===================================================================
--- common/db/textblock.php	(revision 954)
+++ common/db/textblock.php	(working copy)
@@ -285,4 +285,36 @@
     }
 }
 
+function textblock_copy($old_name, $new_name) {
+    $old_name = normalize_page_name($old_name);
+    $new_name = normalize_page_name($new_name);
+    log_assert(is_normal_page_name($old_name));
+    log_assert(is_normal_page_name($new_name));
+
+    $new_textblock = textblock_get_revision($old_name);
+    $new_textblock['name'] = $new_name;
+    db_insert('ia_textblock', $new_textblock);
+
+    // Get a list of attachments.
+    $files = attachment_get_all($old_name);
+
+    // Copy attachments in db and get new id's
+    foreach ($files as &$file) {
+        $id = attachment_insert($file['name'], $file['size'], $file['mime_type'], $new_name, identity_get_user_id());
+        $file['new_id'] = $id;
+    }
+
+    // Copy attachments to hard drive
+    foreach ($files as $file) {
+        $old_filename = attachment_get_filepath($file);
+        $file['page'] = $new_name;
+        $file['id'] = $file['new_id'];
+        $new_filename = attachment_get_filepath($file);
+
+        if (!@copy($old_filename, $new_filename)) {
+            log_error("Failed copying attachment from $old_filename to $new_filename");
+        }
+    }
+}
+
 ?>
Index: common/security.php
===================================================================
--- common/security.php	(revision 954)
+++ common/security.php	(working copy)
@@ -114,6 +114,7 @@
 
         // Irreversible edits.
         case 'textblock-move':
+        case 'textblock-copy':
         case 'attach-overwrite':
         case 'attach-delete':
         case 'attach-rename':
Index: www/controllers/textblock_copy.php
===================================================================
--- www/controllers/textblock_copy.php	(revision 0)
+++ www/controllers/textblock_copy.php	(revision 0)
@@ -0,0 +1,51 @@
+<?php
+
+require_once(IA_ROOT_DIR . "common/db/textblock.php");
+
+// Initial copy controller.
+function controller_textblock_copy($page_name) {
+    // Get actual page.
+    $page = textblock_get_revision($page_name);
+
+    // Check permissions.
+    if ($page) {
+        identity_require('textblock-copy', $page);
+    } else {
+        // Missing page.
+        flash_error("Pagina inexistenta.");
+        redirect(url_home());
+    }
+
+    $values = array();
+    $errors = array();
+
+    if (request_is_post()) {
+        $values['new_name'] = $new_name = request("new_name", "");
+        $new_name = normalize_page_name($new_name);
+
+        if (!is_page_name($new_name)) {
+            $errors['new_name'] = "Nume de pagina invalida";
+        } else if (textblock_get_revision($new_name) !== null) {
+            $errors['new_name'] = "Pagina deja exista";
+        }
+
+        if (!$errors) {
+            textblock_copy($page_name, $new_name);
+            flash("Pagina a fost copiata.");
+            redirect(url_textblock($new_name));
+        }
+    }
+
+    // -- Print form
+    $view = array(
+            'title' => "Copiaza " . $page_name,
+            'page_name' => $page_name,
+            'action' => url_textblock_copy($page_name),
+            'form_values' => $values,
+            'form_errors' => $errors,
+    );
+
+    execute_view_die("views/textblock_copy.php", $view);
+}
+
+?>

Property changes on: www/controllers/textblock_copy.php
___________________________________________________________________
Added: svn:executable
   + *

Index: www/controllers/textblock_move.php
===================================================================
--- www/controllers/textblock_move.php	(revision 954)
+++ www/controllers/textblock_move.php	(working copy)
@@ -47,3 +47,5 @@
 
     execute_view_die("views/textblock_move.php", $view);
 }
+
+?>
Index: www/index.php
===================================================================
--- www/index.php	(revision 954)
+++ www/index.php	(working copy)
@@ -155,6 +155,11 @@
     require_once(IA_ROOT_DIR.'www/controllers/textblock_move.php');
     controller_textblock_move($page);
 }
+//  - copy textblock
+else if ($action == 'copy') {
+    require_once(IA_ROOT_DIR.'www/controllers/textblock_copy.php');
+    controller_textblock_copy($page);
+}
 //  - restore textblock
 else if ($action == 'restore') {
     require_once(IA_ROOT_DIR.'www/controllers/textblock.php');
Index: www/url.php
===================================================================
--- www/url.php	(revision 954)
+++ www/url.php	(working copy)
@@ -106,6 +106,12 @@
     ));
 }
 
+function url_textblock_copy($page_name) {
+    return url_complex($page_name, array(
+            'action' => 'copy'
+    ));
+}
+
 function url_textblock_delete($page_name) {
     return url_complex($page_name, array(
             'action' => 'delete'
Index: www/views/textblock_copy.php
===================================================================
--- www/views/textblock_copy.php	(revision 0)
+++ www/views/textblock_copy.php	(revision 0)
@@ -0,0 +1,22 @@
+<?php include('header.php'); ?>
+
+<h1><?= html_escape($title) ?></h1>
+
+<form action="<?= html_escape(url_textblock_copy($page_name)) ?>" method="post" class="copy clear">
+<fieldset>
+    <ul class="form">
+        <li>
+            <label for="form_new_name">Noul nume</label>
+            <?= ferr_span('new_name') ?>
+            <input type="text" name="new_name" value="<?= fval('new_name') ?>" id="form_new_name" />
+        </li>
+    </ul>
+</fieldset>
+<ul class="form clear">
+    <li>
+        <input type="submit" class="button important" value="Copiaza pagina" id="form_submit" />
+    </li>
+</ul>
+</form>
+
+<?php include('footer.php'); ?>

Property changes on: www/views/textblock_copy.php
___________________________________________________________________
Added: svn:executable
   + *

Index: www/views/textblock_header.php
===================================================================
--- www/views/textblock_header.php	(revision 954)
+++ www/views/textblock_header.php	(working copy)
@@ -18,6 +18,9 @@
 <?php if (identity_can('textblock-move', $textblock)) { ?>
 <li><?= format_link_access(url_textblock_move($textblock['name']), 'Muta', 'u') ?></li>
 <?php } ?>
+<?php if (identity_can('textblock-copy', $textblock)) { ?>
+<li><?= format_link_access(url_textblock_copy($textblock['name']), 'Copiaza', 'c') ?></li>
+<?php } ?>
 <?php if (identity_can('textblock-delete', $textblock)) { ?>
 <li><?= format_post_link(
     url_textblock_delete($textblock['name']),
