[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Phpgroupware-cvs] [20913] Feature : added copy
From: |
Pascal Vilarem |
Subject: |
[Phpgroupware-cvs] [20913] Feature : added copy |
Date: |
Tue, 05 Jan 2010 17:55:30 +0000 |
Revision: 20913
http://svn.sv.gnu.org/viewvc/?view=rev&root=phpgroupware&revision=20913
Author: maat
Date: 2010-01-05 17:55:30 +0000 (Tue, 05 Jan 2010)
Log Message:
-----------
Feature : added copy
Modified Paths:
--------------
modules/ged/trunk/inc/class.flow_client.inc.php
modules/ged/trunk/inc/class.ged_dm.inc.php
Modified: modules/ged/trunk/inc/class.flow_client.inc.php
===================================================================
--- modules/ged/trunk/inc/class.flow_client.inc.php 2010-01-05 17:54:43 UTC
(rev 20912)
+++ modules/ged/trunk/inc/class.flow_client.inc.php 2010-01-05 17:55:30 UTC
(rev 20913)
@@ -122,12 +122,12 @@
return($result);
}
-
+
function is_not_last_version($object)
{
// TODO : Here we need to rework condition to avoid code
duplication
// DEBUG
- //_debug_array($object);
+ //_debug_array($object);
$last_version=$this->ged_dm->get_last_version($object['element_id']);
@@ -929,5 +929,283 @@
}
}
+ function copy($object,$status,$context=null)
+ {
+ $function_result=Array('status' => 'processing');
+
+
+ $version=$this->ged_dm->get_version_info($object['version_id']);
+
$element=$this->ged_dm->get_element_info($version['element_id']);
+
+ // actions
+ $copy_version=$this->get_var('copy_version', array('POST',
'GET'));
+ $go_back=$this->get_var('go_back', array('POST', 'GET'));
+
+
+
+ // needed for 'update_version' action
+
+ $new_major_value=$this->get_var('major', array('POST', 'GET'));
+ $new_minor_value=$this->get_var('minor', array('POST', 'GET'));
+ $new_draft_value=$this->get_var('draft', array('POST', 'GET'));
+
+
+
+
+
+ // needed for relations action
+ $new_relations=$this->get_var('relations', array('POST',
'GET'));
+
+
+
+
+ if ( $context['custom_fields']['copy_mode'] == 'freeze' &&
$copy_version==lang('Freeze') )
+ {
+
+
+ $new_version['element_id']=$version['element_id'];
+ $new_version['file_name']=$version['file_name'];
+ $new_version['file_size']=$version['size'];
+ $new_version['file_tmp_name']=$version['file_full_path'];
+ $new_version['file_mime_type']=$version['mime_type'];
+ $new_version['relations']=$new_relations;
+
+ // TODO : version numbering
+ $new_version['major']=$new_major_value;
+ $new_version['minor']=$new_minor_value;
+ $new_version['draft']=$new_draft_value;
+
+ $new_version['description']=$version['description'];
+
+ $version_added=$this->ged_dm->copy_to_add_version($new_version);
+
+ if ($version_added=='OK')
+ {
+ $function_result=Array('status' =>
'ok');
+
$function_result['comment']=lang('(Copy) ').$version['description'];
+ }
+ else
+ {
+ print ( $version_added);
+ $function_result=Array('status' => 'error');
+ }
+
+ }
+ elseif ( $go_back == lang('Go back'))
+ {
+ $function_result=Array('status' => 'ok', 'mute_history'
=> 'mute');
+ }
+ else
+ {
+ if ( $context['custom_fields']['copy_mode'] == 'freeze'
)
+ {
+ // TODO : Guess next version numbers
+
+ $this->t->set_var('copy_version_action', lang('Freeze'));
+ }
+ }
+ if ( $function_result['status'] != 'ok')
+ {
+
+ if ( (int)$new_major_value != 0 )
+ {
+ $major=$new_major_value;
+ }
+ else
+ {
+ $major=$version['major'];
+ }
+
+ if ( (int)$new_minor_value != 0 )
+ {
+ $minor=$new_minor_value;
+ }
+ else
+ {
+ $minor=$version['minor'];
+ }
+
+ if ( (int)$new_draft_value != 0 )
+ {
+ $draft=$new_draft_value;
+ }
+ else
+ {
+ $draft=$version['draft']+1;
+ }
+
+ /*
+ * Relations
+ *
+ */
+
+
+
+
$version_relations=$this->ged_dm->list_version_relations_out (
$object['version_id'] );
+ //_debug_array($version_relations);
+
+
+
+
+ $new_relations=null;
+ $nri=0;
+ if ( is_array($version_relations))
+ {
+ foreach ( $version_relations as $version_relation )
+ {
+ //print ($version_relation['status'] );
+
+ // NIARF
+ if ( array_key_exists('status', $version_relation) )
+ {
+ if ( $version_relation['status']=='obsolete' ||
$version_relation['status']=='refused' )
+ {
+ // print ( 'new version :
'.$version_relation['version_id']."<br/>\n");
+
+ // TODO : prepare data for future relation
creation
+ // TOFIX : when obsolete or refused without
current version
+ // TOFIX : there is a problem
+
$the_new_relations=$this->ged_dm->get_current_version($version_relation['element_id']);
+
+
$new_relations[$nri]['linked_version_id']=$the_new_relations['version_id'];
+
$new_relations[$nri]['reference']=$version_relation['reference'];
+
$new_relations[$nri]['name']=$version_relation['name'];
+
$new_relations[$nri]['major']=$the_new_relations['major'];
+
$new_relations[$nri]['minor']=$the_new_relations['minor'];
+
$new_relations[$nri]['draft']=$the_new_relations['draft'];
+
$new_relations[$nri]['status']=$the_new_relations['status'];
+
+ // TODO : use real value
+
$new_relations[$nri]['relation_type']='dependancy';
+
+ $nri++;
+ }
+ else
+ {
+ // print ( 'report :
'.$version_relation['version_id']."<br/>\n");
+
+ // TODO : prepare data for future relation
creation
+
$new_relations[$nri]['linked_version_id']=$version_relation['version_id'];
+
$new_relations[$nri]['major']=$version_relation['major'];
+
$new_relations[$nri]['minor']=$version_relation['minor'];
+
$new_relations[$nri]['draft']=$version_relation['draft'];
+
$new_relations[$nri]['status']=$version_relation['status'];
+
$new_relations[$nri]['reference']=$version_relation['reference'];
+
$new_relations[$nri]['name']=$version_relation['name'];
+
$new_relations[$nri]['relation_type']=$version_relation['relation_type'];
+
+ $nri++;
+ }
+ }
+ else
+ {
+ // TODO : prepare data for future relation
creation
+
$new_relations[$nri]['linked_version_id']=$version_relation['version_id'];
+
$new_relations[$nri]['major']=$version_relation['major'];
+
$new_relations[$nri]['minor']=$version_relation['minor'];
+
$new_relations[$nri]['draft']=$version_relation['draft'];
+
$new_relations[$nri]['status']=$version_relation['status'];
+
$new_relations[$nri]['reference']=$version_relation['reference'];
+
$new_relations[$nri]['name']=$version_relation['name'];
+
$new_relations[$nri]['relation_type']='dependancy';
+
+ $nri++;
+ }
+ }
+ }
+
+ $this->t->set_file(array('copy_file_tpl'=>'copy.tpl'));
+ $this->load_template_defaults();
+ $this->display_app_header();
+ $this->t->set_var('element_id_value',
$object['element_id']);
+
+
+ /*
+ * Generic display data
+ */
+
+ $this->t->set_var('reset_file_field', 'reset_file');
+ $this->t->set_var('reset_file_action', lang('Undo'));
+
+
+ $this->t->set_var('copy_version_field', 'copy_version');
+
+ $this->t->set_var('reset_version_field',
'reset_version');
+ $this->t->set_var('reset_version_action', lang('Undo'));
+
+
+
+ $this->t->set_var('go_back_field', 'go_back');
+ $this->t->set_var('go_back_action', lang('Go back'));
+
+ $this->t->set_var('element_id_field', 'element_id');
+
+
+ $this->t->set_var('major_field', 'major');
+ $this->t->set_var('minor_field', 'minor');
+ $this->t->set_var('draft_field', 'draft');
+ $this->t->set_var('major_value', $major);
+ $this->t->set_var('minor_value', $minor);
+ $this->t->set_var('draft_value', $draft);
+
+
+ }
+
+ $this->t->pfp('out', 'copy_file_tpl');
+ return ($function_result);
+ }
+
+ function apply_transition_to_current($object,$trigger_context=null)
+ {
+ // DONE : set as parameter
+ $transition=$trigger_context['transition'];
+ $sub_flow=CreateObject('ged.flows');
+ $status_from=$sub_flow->get_transition_status_from($transition);
+
+
$versions=$this->ged_dm->get_previous_versions_matching_status($object['version_id'],$status_from);
+
+ // CARE : triggered transition should always be 'automatic' ones
+
+
+ $do_transition_result=$sub_flow->do_transition($transition,
$object);
+
+ }
+
+ function notification_filter($users,$object,$trigger_context=null)
+ {
+
+ $final_users_list = array();
+ $cpt = 0;
+ $project = $object['project_root'];
+ $action =
$this->ged_dm->get_action($this->get_var('transition', array('POST', 'GET')));
+ foreach($users as $user)
+ {
+ $mail =
$this->ged_dm->notification_filter($user,$project,$action);
+ if($mail)
+ $final_users_list[$cpt++]=$mail;
+ }
+
+ return $final_users_list;
+
+ }
+ function custom_message($object)
+ {
+ $custom_message = array();
+ $doc_info =
$this->ged_dm->get_element_info($object['element_id']);
+ $version_info =
$this->ged_dm->get_version_info($object['version_id']);
+ $action =
$this->ged_dm->get_action($this->get_var('transition', array('POST', 'GET')));
+ $link_data=null;
+ $link_data['menuaction']='ged.ged_ui.browse';
+ $link_data['focused_id']=$object['element_id'];
+ $link_data['version_id']=$object['version_id'];
+
+ $url_version=$GLOBALS['phpgw']->link('/index.php', $link_data);
+ $custom_message['html'] = lang("Action")."
<b>".$action."</b>".lang(" was made on the document ")."<a
href=\"http://".$_SERVER['HTTP_HOST']."$url_version\">".$doc_info['name'].".</a><br/><br/>".lang("Project")."
: <b>".$doc_info['project_name']."</b><br/>".lang("Document")." :
".$doc_info['name']."<br/>".lang("Version")." :
".$version_info['major'].".".$version_info['minor'].".".$version_info['draft'];
+ $custom_message['texte'] = lang("Action")." ".$action."".lang("
was made on the document ").$doc_info['name'].".\n\n".lang("Project")." :
".$doc_info['project_name']."\n".lang("Document")." :
".$doc_info['name']."\n".lang("Version")." :
".$version_info['major'].".".$version_info['minor'].".".$version_info['draft']."\n".lang("link")."
: "."http://".$_SERVER['HTTP_HOST'].$url_version;
+ $custom_message['sujet'] = $doc_info['project_name']." -
".$doc_info['name'];
+
+ return $custom_message;
+ }
+
}
Modified: modules/ged/trunk/inc/class.ged_dm.inc.php
===================================================================
--- modules/ged/trunk/inc/class.ged_dm.inc.php 2010-01-05 17:54:43 UTC (rev
20912)
+++ modules/ged/trunk/inc/class.ged_dm.inc.php 2010-01-05 17:55:30 UTC (rev
20913)
@@ -275,6 +275,96 @@
}
+ function add_file_copy($new_file)
+ {
+
+ // MEMO gestion du stored_name pour eviter les ecrasements.
+
+ $basename=basename($new_file['file_name']);
+ $candidate_name=$basename;
+
+ $extension=$this->get_file_extention($basename);
+
+ $parent=$this->get_element_info($new_file['parent_id']);
+
+ $i=0;
+
+ while (file_exists($this->datadir."/".$candidate_name))
+ {
+ $i ++;
+ $candidate_name="v".$i."_".$basename;
+ }
+
+ $new_name=$this->datadir."/".$candidate_name;
+
+ if (copy($new_file['file_tmp_name'], $new_name))
+ {
+
+ $download_result='OK';
+
+ }
+ else
+ {
+
+ $download_result='NOK';
+ print ('NOOK FILE MOVE');
+ return 'NOK';
+
+ }
+
+ // TODO : If the document type requires a chrono
+ // TODO : generate reference and override the reference
+ // TODO : given by user if needed
+ if ( !isset($new_file['reference']) ||
((int)$parent['project_root'] != 0 &&
$this->is_chrono_type($new_file['doc_type'])))
+ {
+
$next_ref=$this->get_next_available_reference($new_file['doc_type'],
$parent['project_root'] );
+ }
+ else
+ {
+ $next_ref=$new_file['reference'];
+ }
+
+ if ($download_result=='OK')
+ {
+ // DONE : ADD 'validity_period'
+ $sql_model="INSERT INTO %s ( type, parent_id, name,
reference, description, owner_id, creator_id, creation_date, doc_type,
validity_period, project_name, project_root) VALUES ";
+ $sql_model.=" ( '%s', %d, '%s', '%s', '%s', %d, %d, %d,
'%s', %d, '%s', %d ) ";
+
+ $sql=sprintf($sql_model, $this->tables['elements'],
'file', $new_file['parent_id'], $new_file['name'], $next_ref,
$new_file['description'], $GLOBALS['phpgw_info']['user']['account_id'],
$GLOBALS['phpgw_info']['user']['account_id'], time(), $new_file['doc_type'],
$new_file['validity_period'],$parent['project_name'],$parent['project_root']);
+
+ // DONE gestion des slashes !
+ //print ($sql);
+
+ $this->db->query($sql, __LINE__, __FILE__);
+ //recuperer l'id
+
$new_element_id=$this->db->get_last_insert_id($this->tables['elements'],
'element_id');
+
+ $this->db->unlock();
+
+ // DONE gestion des slashes
+
+ $sql_model1="INSERT INTO %s ( size, file_name,
stored_name, file_extension, creator_id, creation_date, status, element_id,
description, major, minor, draft ) VALUES ";
+ $sql_model1.=" ( %d, '%s', '%s', '%s', %d, %d, '%s',
%d, '%s', %d, %d, %d ) ";
+
+ $major=(int)$new_file['major'];
+ $minor=(int)$new_file['minor'];
+ $draft=(int)$new_file['draft'];
+
+ $sql1=sprintf($sql_model1, $this->tables['versions'],
$new_file['file_size'], addslashes($new_file['file_name']),
addslashes($candidate_name), $extension,
$GLOBALS['phpgw_info']['user']['account_id'], time(), 'working',
$new_element_id, $new_file['descriptionv'], $major, $minor, $draft);
+
+ //print ("<br/>".$sql1);
+
+ $this->db->query($sql1, __LINE__, __FILE__);
+ $this->db->unlock();
+
+ $this->set_default_acl($new_element_id);
+
+ return ( $new_element_id );
+
+ }
+
+ }
+
function update_file($new_file)
{
$myelement=$this->get_element_info($new_file['element_id']);
@@ -560,6 +650,93 @@
}
+ function copy_to_add_version($new_version)
+ {
+ if ( $this->debug('add_version') )
+ print ( "add_version: entering.<br>\n");
+
+
$last_version=$this->get_last_version($new_version['element_id']);
+
+ // MEMO gestion des numeros de versions
+ $major=$new_version['major'];
+ $minor=$new_version['minor'];
+ $draft=$new_version['draft'];
+
+ if ( ($major < $last_version['major']) ||
+ ($major == $last_version['major'] && $minor <
$last_version['minor']) ||
+ ($major == $last_version['major'] && $minor ==
$last_version['minor'] && $draft <= $last_version['draft']) )
+ {
+ $major=$last_version['major'];
+ $minor=$last_version['minor'];
+ $draft=$last_version['draft']+1;
+ }
+
+ // MEMO gestion du stored_name pour eviter les ecrasements.
+
+ $basename=basename($new_version['file_name']);
+ $candidate_name=$basename;
+
+ $extension=$this->get_file_extention($basename);
+
+ $i=0;
+
+ while (file_exists($this->datadir."/".$candidate_name))
+ {
+ $i ++;
+ $candidate_name="v".$i."_".$basename;
+ }
+
+ $new_name=$this->datadir."/".$candidate_name;
+
+ if (copy($new_version['file_tmp_name'], $new_name))
+ {
+
+ $download_result='OK';
+
+ }
+ else
+ return "PB download";
+
+ // MEMO attention que if $new_version['status'] est current il
faut rendre obsolète la "vieille"
+
+ if ($download_result=='OK')
+ {
+
+ $sql_model1="INSERT INTO %s ( size, file_name,
stored_name, file_extension, creator_id, creation_date, status, element_id,
description, major, minor, draft ) VALUES ";
+ $sql_model1.=" ( %d, '%s', '%s', '%s', %d, %d, '%s',
%d, '%s', %d, %d, %d ) ";
+
+ $sql1=sprintf($sql_model1, $this->tables['versions'],
$new_version['file_size'], addslashes($new_version['file_name']),
addslashes($candidate_name), $extension,
$GLOBALS['phpgw_info']['user']['account_id'], time(), 'working',
$new_version['element_id'], $this->cleanstr($new_version['description']),
$major, $minor, $draft);
+
+ //print ("<br/>".$sql1);
+
+ $this->db->query($sql1, __LINE__, __FILE__);
+
+
$my_new_version_id=$new_element_id=$this->db->get_last_insert_id($this->tables['versions'],
'version_id');
+
+ $this->db->unlock();
+
+
+
+ }
+
+ // AJOUT des relations
+ if ( is_array($new_version['relations']))
+ {
+ foreach ( $new_version['relations'] as $relation )
+ {
+ $sql3="INSERT INTO ged_relations (
linked_version_id, linking_version_id, relation_type) values (
".$relation['linked_version_id'].",".$my_new_version_id.",'".$relation['relation_type']."'
);";
+ $this->db->query($sql3, __LINE__, __FILE__);
+ $this->db->unlock();
+ }
+ }
+
+ if ( $this->debug('add_version') )
+ print ( "add_version: end.<br>\n");
+
+ return "OK";
+
+ } // EOF copy_to_add_version
+
function update_version($amended_version)
{
@@ -3683,7 +3860,7 @@
return ($out);
}
-
+
function get_project_status($project_root)
{
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Phpgroupware-cvs] [20913] Feature : added copy,
Pascal Vilarem <=