[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Fmsystem-commits] [16189] Backport diff from Syncromind to trunk
From: |
sigurdne |
Subject: |
[Fmsystem-commits] [16189] Backport diff from Syncromind to trunk |
Date: |
Wed, 25 Jan 2017 03:47:46 -0500 (EST) |
Revision: 16189
http://svn.sv.gnu.org/viewvc/?view=rev&root=fmsystem&revision=16189
Author: sigurdne
Date: 2017-01-25 03:47:46 -0500 (Wed, 25 Jan 2017)
Log Message:
-----------
Backport diff from Syncromind to trunk
Modified Paths:
--------------
trunk/phpgwapi/inc/class.db.inc.php
trunk/phpgwapi/inc/class.db_pdo.inc.php
trunk/phpgwapi/js/jquery/file-upload/css/jquery.fileupload-custom.css
trunk/property/inc/class.soentity.inc.php
trunk/property/inc/class.sogeneric_document.inc.php
trunk/property/inc/class.uientity.inc.php
trunk/property/inc/class.uiimport_components.inc.php
trunk/property/inc/class.uilocation.inc.php
trunk/property/inc/import/class.import_component_files.inc.php
trunk/property/js/portico/admin_entity.edit_category.js
trunk/property/js/portico/import_components.js
trunk/property/templates/base/admin_entity.xsl
trunk/property/templates/base/multi_upload_file.xsl
Property Changed:
----------------
trunk/
trunk/booking/
trunk/bookingfrontend/
Index: trunk
===================================================================
--- trunk 2017-01-25 08:38:31 UTC (rev 16188)
+++ trunk 2017-01-25 08:47:46 UTC (rev 16189)
Property changes on: trunk
___________________________________________________________________
Modified: svn:mergeinfo
## -1,3 +1,3 ##
/branches/dev-syncromind:13653
-/branches/dev-syncromind-2:14933-16129
+/branches/dev-syncromind-2:14933-16188
/branches/stavangerkommune:12743-12875,12986
\ No newline at end of property
Index: trunk/booking
===================================================================
--- trunk/booking 2017-01-25 08:38:31 UTC (rev 16188)
+++ trunk/booking 2017-01-25 08:47:46 UTC (rev 16189)
Property changes on: trunk/booking
___________________________________________________________________
Modified: svn:mergeinfo
## -1,2 +1,2 ##
-/branches/dev-syncromind-2/booking:14933-16129
+/branches/dev-syncromind-2/booking:14933-16188
/branches/stavangerkommune/booking:9468-12740,12743-12875,12986
\ No newline at end of property
Index: trunk/bookingfrontend
===================================================================
--- trunk/bookingfrontend 2017-01-25 08:38:31 UTC (rev 16188)
+++ trunk/bookingfrontend 2017-01-25 08:47:46 UTC (rev 16189)
Property changes on: trunk/bookingfrontend
___________________________________________________________________
Modified: svn:mergeinfo
## -1,2 +1,2 ##
-/branches/dev-syncromind-2/bookingfrontend:14933-16129
+/branches/dev-syncromind-2/bookingfrontend:14933-16188
/branches/stavangerkommune/bookingfrontend:9468-12740,12986
\ No newline at end of property
Modified: trunk/phpgwapi/inc/class.db.inc.php
===================================================================
--- trunk/phpgwapi/inc/class.db.inc.php 2017-01-25 08:38:31 UTC (rev 16188)
+++ trunk/phpgwapi/inc/class.db.inc.php 2017-01-25 08:47:46 UTC (rev 16189)
@@ -412,7 +412,7 @@
{
if ( is_numeric($value) )
{
- $insert_value[] = "'$value'";
+ $insert_value[] = "'{$value}'";
}
else
{
@@ -419,6 +419,10 @@
$insert_value[] = "'" .
$this->db_addslashes(stripslashes($value)) . "'"; //in case slashes are already
added.
}
}
+ else if($value && $this->isJson($value))
+ {
+ $insert_value[] = "'{$value}'";
+ }
else
{
$insert_value[] = 'NULL';
@@ -427,6 +431,12 @@
return implode(",", $insert_value);
}
+ final public function isJson($string)
+ {
+ json_decode($string);
+ return (json_last_error() == JSON_ERROR_NONE);
+ }
+
/**
* Prepare the SET component of an UPDATE sql statement
*
@@ -461,6 +471,10 @@
$value_entry[]=
"{$field}='{$value}'";
}
}
+ else if($value && $this->isJson($value))
+ {
+ $value_entry[]= "{$field}='{$value}'";
+ }
else
{
$value_entry[]= "{$field}=NULL";
Modified: trunk/phpgwapi/inc/class.db_pdo.inc.php
===================================================================
--- trunk/phpgwapi/inc/class.db_pdo.inc.php 2017-01-25 08:38:31 UTC (rev
16188)
+++ trunk/phpgwapi/inc/class.db_pdo.inc.php 2017-01-25 08:47:46 UTC (rev
16189)
@@ -831,8 +831,11 @@
{
if ($strip_slashes ||
($this->auto_stripslashes && ! $strip_slashes))
{
- return
htmlspecialchars_decode(stripslashes(str_replace(array('&','(',
')', '=','−−',';'), array('&','(', ')', '=', '--',';'),
$this->Record[$name])),ENT_QUOTES);
-// return
htmlspecialchars_decode(stripslashes($this->Record[$name]));
+ // $str =
preg_replace_callback('/\\\\u([0-9a-fA-F]{4})/', function ($match){
+ $str =
preg_replace_callback('/u([0-9a-fA-F]{4})/', function ($match){
+ return
mb_convert_encoding(pack('H*', $match[1]), 'UTF-8', 'UTF-16BE');
+ }, $this->Record[$name]);
+ return
htmlspecialchars_decode(stripslashes(str_replace(array('&','(',
')', '=','−−',';'), array('&','(', ')', '=', '--',';'),
$str)),ENT_QUOTES);
}
else
{
Modified: trunk/phpgwapi/js/jquery/file-upload/css/jquery.fileupload-custom.css
===================================================================
--- trunk/phpgwapi/js/jquery/file-upload/css/jquery.fileupload-custom.css
2017-01-25 08:38:31 UTC (rev 16188)
+++ trunk/phpgwapi/js/jquery/file-upload/css/jquery.fileupload-custom.css
2017-01-25 08:47:46 UTC (rev 16189)
@@ -11,6 +11,12 @@
vertical-align: bottom;
margin-left: 10px;
}
+.fileupload-count {
+ display: inline-block;
+ margin-bottom: 10px;
+ vertical-align: bottom;
+ margin-left: 10px;
+}
.error {
color: red;
}
Modified: trunk/property/inc/class.soentity.inc.php
===================================================================
--- trunk/property/inc/class.soentity.inc.php 2017-01-25 08:38:31 UTC (rev
16188)
+++ trunk/property/inc/class.soentity.inc.php 2017-01-25 08:47:46 UTC (rev
16189)
@@ -350,7 +350,7 @@
$j = 0;
while ($this->db->next_record())
{
- $jsondata =
json_decode($this->db->f('json_representation'), true);
+ $jsondata =
json_decode($this->db->f('json_representation', true), true);
// $xml = new DOMDocument('1.0', 'utf-8');
// $xml->loadXML($xmldata);
@@ -1056,7 +1056,7 @@
// $xmldata = $this->db->f('xml_representation');
// $xml = new DOMDocument('1.0', 'utf-8');
// $xml->loadXML($xmldata);
- $jsondata =
json_decode($this->db->f('json_representation'), true);
+ $jsondata =
json_decode($this->db->f('json_representation', true), true);
foreach ($cols_return as $key => $field)
{
@@ -2062,7 +2062,7 @@
{
foreach ($values['attributes'] as
&$attr)
{
- $attr['value'] =
$this->db->f($attr['column_name']);
+ $attr['value'] =
$this->db->f($attr['column_name'], true);
}
}
}
@@ -2119,7 +2119,7 @@
// $xml = new DOMDocument('1.0', 'utf-8');
// $xml->loadXML($xmldata);
- $jsondata =
json_decode($this->db->f('json_representation'), true);
+ $jsondata =
json_decode($this->db->f('json_representation', true), true);
if (isset($values['attributes']) &&
is_array($values['attributes']))
{
@@ -2621,7 +2621,7 @@
// $xml = new
DOMDocument('1.0', 'utf-8');
// $xml->loadXML($xmldata);
// $old_value =
$xml->getElementsByTagName($entry['name'])->item(0)->nodeValue;
- $jsondata =
json_decode($this->db->f('json_representation'), true);
+ $jsondata =
json_decode($this->db->f('json_representation', true), true);
$old_value =
$jsondata[$entry['name']];
}
Modified: trunk/property/inc/class.sogeneric_document.inc.php
===================================================================
--- trunk/property/inc/class.sogeneric_document.inc.php 2017-01-25 08:38:31 UTC
(rev 16188)
+++ trunk/property/inc/class.sogeneric_document.inc.php 2017-01-25 08:47:46 UTC
(rev 16189)
@@ -53,6 +53,7 @@
$user_id = isset($data['user_id']) && $data['user_id']
? (int)$data['user_id'] : 0;
$cat_id = isset($data['cat_id']) && $data['cat_id'] ?
(int)$data['cat_id'] : 0;
$location_id = isset($data['location_id']) &&
$data['location_id'] ? (int)$data['location_id'] : 0;
+ $location_item_id = isset($data['location_item_id']) &&
$data['location_item_id'] ? (int)$data['location_item_id'] : 0;
$mime_type = isset($data['mime_type']) ?
$data['mime_type'] : '';
$start_date = isset($data['start_date']) ?
$data['start_date'] : 0;
$end_date = isset($data['end_date']) ?
$data['end_date'] : 0;
@@ -94,6 +95,11 @@
$filtermethod .= " AND c.location_id =
{$location_id}";
}
+ if($location_item_id)
+ {
+ $filtermethod .= " AND c.location_item_id =
{$location_item_id}";
+ }
+
if ($user_id)
{
$filtermethod .= " AND a.createdby_id =
{$user_id}";
Modified: trunk/property/inc/class.uientity.inc.php
===================================================================
--- trunk/property/inc/class.uientity.inc.php 2017-01-25 08:38:31 UTC (rev
16188)
+++ trunk/property/inc/class.uientity.inc.php 2017-01-25 08:47:46 UTC (rev
16189)
@@ -2117,7 +2117,6 @@
{
$location_id =
$GLOBALS['phpgw']->locations->get_id($this->type_app[$this->type],
$this->acl_location);
- $get_docs = false;
$check_doc =
$this->bocommon->get_lookup_entity('document');
foreach ($check_doc as $_check)
{
@@ -2130,6 +2129,8 @@
if ($get_docs ||
!empty($entity['documentation']))
{
+ $get_docs = true;
+
$tabs['document'] = array('label' =>
lang('document'), 'link' => '#document', 'disable' => 0);
$cats =
CreateObject('phpgwapi.categories', -1, 'property', '.document');
Modified: trunk/property/inc/class.uiimport_components.inc.php
===================================================================
--- trunk/property/inc/class.uiimport_components.inc.php 2017-01-25
08:38:31 UTC (rev 16188)
+++ trunk/property/inc/class.uiimport_components.inc.php 2017-01-25
08:47:46 UTC (rev 16189)
@@ -71,9 +71,6 @@
public function download()
{
- /*$config = createObject('phpgwapi.config',
'component_import');
- $values = $config->read_repository();*/
- //$components =
$this->config_repository['preview_components'];
$components = phpgwapi_cache::session_get('property',
'preview_components');
$components = ($components) ? unserialize($components)
: array();
@@ -122,8 +119,8 @@
public function import_component_files()
{
$location_code = phpgw::get_var('location_code');
- $id = phpgw::get_var('location_item_id');
- $attrib_name_componentID =
phpgw::get_var('attribute_name_component_id');
+ //$id = phpgw::get_var('location_item_id');
+ //$attrib_name_componentID =
phpgw::get_var('attribute_name_component_id');
$preview = phpgw::get_var('preview');
$with_components =
phpgw::get_var('with_components_check');
@@ -152,9 +149,9 @@
if ($with_components)
{
- $receipt =
$import_component_files->add_files_components_location($id, $location_code,
$attrib_name_componentID);
+ $receipt =
$import_component_files->add_files_components_location();
} else {
- $receipt =
$import_component_files->add_files_location($id, $location_code);
+ $receipt =
$import_component_files->add_files_location();
}
return $receipt;
@@ -406,6 +403,7 @@
private function _prepare_profile ()
{
$columns = (array) phpgw::get_var('columns');
+ $attrib_names = (array) phpgw::get_var('attrib_names');
$template_id = phpgwapi_cache::session_get('property',
'template_id');
$attrib_name_componentID =
phpgwapi_cache::session_get('property', 'attrib_name_componentID');
@@ -430,10 +428,11 @@
{
if ($v == 'new_column')
{
- unset($columns[$k]);
- continue;
+ $columns_name[] = $k .' =>
'.$attrib_names[$k];
+ $columns[$k] =
strtolower($attrib_names[$k]);
+ } else {
+ $columns_name[] = $k .' =>
'.$_options[$v];
}
- $columns_name[] = $k .' => '.$_options[$v];
}
$entity_info = $this->bo->read_single($entity_id);
@@ -500,8 +499,7 @@
foreach ($columns as $_row_key => $_value_key)
{
- $_result[$_value_key] =
$objPHPExcel->getActiveSheet()->getCell("{$_row_key}{$i}")->getCalculatedValue();
- }
+ $_result[$_value_key] =
htmlspecialchars($objPHPExcel->getActiveSheet()->getCell("{$_row_key}{$i}")->getCalculatedValue(),
ENT_QUOTES, 'UTF-8'); }
if ((int)$_result['building_part'] ||
$_result['building_part'] === '0')
{
@@ -589,11 +587,6 @@
$profile = $this->_prepare_profile();
$result['profile'] = $profile;
-
- /*$this->config->value('building_part_in_table',
serialize($building_part_in_table));
- $this->config->value('preview_components',
serialize($preview_components));
- $this->config->value('new_components',
serialize($import_data));
- $this->config->save_repository();*/
phpgwapi_cache::session_set('property',
'building_part_in_table', serialize($building_part_in_table));
phpgwapi_cache::session_set('property',
'preview_components', serialize($preview_components));
@@ -630,9 +623,6 @@
return;
}
- /*$config = createObject('phpgwapi.config',
'component_import');
- $config_repository = $config->read_repository();*/
- //$import_data =
$this->config_repository['new_components'];
$import_data = phpgwapi_cache::session_get('property',
'new_components');
$import_data = ($import_data) ?
unserialize($import_data) : array();
@@ -872,8 +862,7 @@
public function get_attributes_from_template()
{
- //$profile = $this->config_repository['profile'];
-
+ $selected_attribute =
phpgw::get_var('selected_attribute');
$category_template =
phpgw::get_var('category_template');
$template_info = explode('_', $category_template);
@@ -884,8 +873,8 @@
$list = array();
foreach ($attrib_list as $attrib)
{
- //$selected =
($profile['attrib_name_componentID']['id'] == $attrib['column_name']) ? 1 : 0;
- $list[] = array('id' => $attrib['column_name'],
'name' => $attrib['input_text']);
+ $selected = ($selected_attribute ==
$attrib['column_name']) ? 1 : 0;
+ $list[] = array('id' => $attrib['column_name'],
'name' => $attrib['input_text'], 'selected' => $selected);
}
array_unshift($list, array('id' => '', 'name' =>
lang('choose attribute')));
Modified: trunk/property/inc/class.uilocation.inc.php
===================================================================
--- trunk/property/inc/class.uilocation.inc.php 2017-01-25 08:38:31 UTC (rev
16188)
+++ trunk/property/inc/class.uilocation.inc.php 2017-01-25 08:47:46 UTC (rev
16189)
@@ -1720,6 +1720,7 @@
$location_id =
$GLOBALS['phpgw']->locations->get_id('property', '.location.' .
count(explode('-', $location_code)));
$generic_document =
CreateObject('property.sogeneric_document');
$params['location_id'] = $location_id;
+ $params['location_item_id'] = $this->bo->get_item_id(
$location_code );
$params['order'] = 'name';
$params['cat_id'] = $doc_type;
$documents2 = $generic_document->read($params);
Modified: trunk/property/inc/import/class.import_component_files.inc.php
===================================================================
--- trunk/property/inc/import/class.import_component_files.inc.php
2017-01-25 08:38:31 UTC (rev 16188)
+++ trunk/property/inc/import/class.import_component_files.inc.php
2017-01-25 08:47:46 UTC (rev 16189)
@@ -12,6 +12,10 @@
$this->fakebase = '/temp_files_components';
$this->path_upload_dir =
$GLOBALS['phpgw_info']['server']['files_dir'].$this->fakebase.'/';
+ $this->location_code = phpgw::get_var('location_code');
+ $this->location_item_id =
phpgw::get_var('location_item_id');
+ $this->attrib_name_componentID =
phpgw::get_var('attribute_name_component_id');
+
$this->last_files_added = array();
$this->list_component_id = array();
$this->paths_from_file = array();
@@ -68,6 +72,7 @@
return true;
}
+ /*
private function _get_files_by_component($id, $location_id)
{
$sql = "SELECT a.location_id, a.location_item_id,
b.file_id, b.name, b.md5_sum FROM phpgw_vfs_file_relation a INNER JOIN
phpgw_vfs b "
@@ -85,21 +90,51 @@
}
return $values;
+ }*/
+
+ private function _get_files_by_component($id, $location_id)
+ {
+ $sql = "SELECT a.location_id, a.location_item_id,
b.file_id, b.name, b.md5_sum FROM phpgw_vfs_file_relation a INNER JOIN
phpgw_vfs b "
+ . " ON a.file_id = b.file_id WHERE
a.location_item_id = '{$id}' AND a.location_id = '{$location_id}'"
+ . " AND b.mime_type != 'Directory' AND
b.mime_type != 'journal' AND b.mime_type != 'journal-deleted'";
+
+ $this->db->query($sql, __LINE__, __FILE__);
+
+ $values = array();
+
+ while ($this->db->next_record())
+ {
+ $values[] = $this->db->f('md5_sum');
+ }
+
+ return $values;
}
- private function _search_in_last_files_added($file_data)
+ private function _search_file_in_db($md5_sum)
{
- $val_md5sum = $file_data['val_md5sum'];
- $file_id = array_search($val_md5sum,
$this->last_files_added);
- if ($file_id)
+ $sql = "SELECT file_id, md5_sum FROM phpgw_vfs "
+ . " WHERE md5_sum = '{$md5_sum}'"
+ . " AND mime_type != 'Directory' AND
mime_type != 'journal' AND mime_type != 'journal-deleted'";
+
+ $this->db->query($sql, __LINE__, __FILE__);
+
+ if ($this->db->next_record())
{
- return $file_id;
+ $id = $this->db->f('file_id');
}
+
+ return $id;
+ }
+
+ private function _search_in_last_files_added($file_data)
+ {
+ $md5sum = $file_data['md5sum'];
+ $file_id = array_search($md5sum,
$this->last_files_added);
- return false;
+ return $file_id;
}
- public function add_files_location($id, $location_code)
+ public function add_files_location()
{
@set_time_limit(5 * 60);
@@ -110,17 +145,19 @@
$count_new_relations = 0;
$count_relations_existing = 0;
+ $files_existing = array();
$count_new_files = 0;
-
//print_r($this->paths_from_file).'<br>'.print_r($uploaded_files); die;
- $component = array('id' => $id, 'location_id' =>
$GLOBALS['phpgw']->locations->get_id('property',
'.location.'.count(explode('-', $location_code))));
+
+ $component = array('id' => $this->location_item_id,
'location_id' => $GLOBALS['phpgw']->locations->get_id('property',
'.location.'.count(explode('-', $this->location_code))));
$files_in_component =
$this->_get_files_by_component($component['id'], $component['location_id']);
foreach ($uploaded_files as $file_data)
{
- if (in_array(str_replace(' ', '_',
$file_data['val_md5sum']), $files_in_component))
+ if (in_array($file_data['md5sum'],
$files_in_component))
{
$count_relations_existing++;
+ $files_existing[$file_data['md5sum']] =
$file_data['md5sum'];
continue;
}
@@ -134,22 +171,29 @@
$file_id =
$this->_search_in_last_files_added($file_data);
if (!$file_id)
{
- $file_id =
$this->_save_file($file_data);
+ $file_id =
$this->_search_file_in_db($file_data['md5sum']);
if (!$file_id)
+ {
+ $file_id =
$this->_save_file($file_data);
+ if (!$file_id)
+ {
+ throw new
Exception("failed to copy file '{$file_data['path_absolute']}'");
+ }
+
unlink($file_data['path_absolute']);
+ $count_new_files++;
+ } else {
+
$files_existing[$file_data['md5sum']] = $file_data['md5sum'];
+ }
+
+ $result =
$this->_save_file_relation($component['id'], $component['location_id'],
$file_id);
+ if (!$result)
{
- throw new
Exception("failed to copy file '{$file_data['path_file']}'");
- }
- unlink($file_data['path_file']);
- $count_new_files++;
+ $message['error'][] =
array('msg' => "failed to save relation. File: '{$file}'");
+ } else {
+
$this->last_files_added[$file_id] = $file_data['md5sum'];
+ $count_new_relations++;
+ }
}
-
- $result =
$this->_save_file_relation($component['id'], $component['location_id'],
$file_id);
- if (!$result)
- {
- $message['error'][] =
array('msg' => "failed to save relation. File: '{$file}'");
- } else {
- $count_new_relations++;
- }
$this->db->Exception_On_Error = false;
}
@@ -174,6 +218,9 @@
} else {
$message['message'][] = array('msg' => lang('%1
files copy', $count_new_files));
}
+ if (count($files_existing)){
+ $message['message'][] = array('msg' => lang('%1
files existing in db', count($files_existing)));
+ }
if ($count_new_relations)
{
$message['message'][] = array('msg' => lang('%1
relations saved successfully', $count_new_relations));
@@ -188,6 +235,20 @@
return $message;
}
+ private function _generate_md5sum($path)
+ {
+ $output = array();
+ exec('md5sum "'.$path.'" 2>&1', $output, $ret);
+ if ($ret)
+ {
+ $md5sum = '';
+ } else {
+ $md5sum = trim(strstr($output[0], ' ', true));
+ }
+
+ return $md5sum;
+ }
+
private function _compare_names(&$component_files,
$uploaded_files)
{
if (count($component_files))
@@ -200,25 +261,27 @@
{
if
(strtolower($file['file']) == strtolower($file_data['file']))
{
- if
($file['path_file_string'])
+ if
($file['path_string'])
{
- $pos =
stripos($file['path_file_string'], $file_data['path_file_string']);
+ $pos =
stripos($file['path_string'], $file_data['path_string']);
if
($pos !== false)
{
-
$file_data['path_file'] = $file['path_file'];
-
$file_data['val_md5sum'] = $file['val_md5sum'];
+
$file_data['path_absolute'] = $file['path_absolute'];
+
$file_data['path_relative'] = $file['path_relative'];
+
$file_data['md5sum'] = $this->_generate_md5sum($file['path_absolute']);
}
} else {
-
$file_data['path_file'] = $file['path_file'];
-
$file_data['val_md5sum'] = $file['val_md5sum'];
+
$file_data['path_absolute'] = $file['path_absolute'];
+
$file_data['path_relative'] = $file_data['path'];
+
$file_data['md5sum'] = $this->_generate_md5sum($file['path_absolute']);
}
}
}
- if
(!empty($file_data['val_md5sum']))
+ if
(!empty($file_data['md5sum']))
{
-
$this->paths_from_file[$file_data['val_md5sum']][] = $file_data['path'];
+
$this->paths_from_file[$file_data['md5sum']][] = $file_data['path_relative'];
} else {
-
$this->paths_empty[$file_data['path_file_string']] =
$file_data['path'].'/'.$file_data['file'];
+
$this->paths_empty[strtolower($file_data['file'])] =
$file_data['path'].'/'.$file_data['file'];
}
}
}
@@ -225,11 +288,12 @@
} else {
foreach ($uploaded_files as $file)
{
- if (!empty($file['val_md5sum']))
+ $md5sum =
$this->_generate_md5sum($file['path_absolute']);
+ if (!empty($md5sum))
{
-
$this->paths_from_file[$file['val_md5sum']][] = dirname($file['path_file']);
+
$this->paths_from_file[$md5sum][] = $file['path_relative'];
} else {
- $this->paths_empty[] =
$file['path_file'];
+ $this->paths_empty[] =
$file['path_absolute'];
}
}
$component_files = $uploaded_files;
@@ -245,7 +309,8 @@
{
for($i = 0; $i < $zip->numFiles; $i++)
{
- $file_name = str_replace('..', '.',
iconv("CP850", "UTF-8", $zip->getNameIndex($i)));
+// $file_name = str_replace('..', '.',
iconv("CP850", "UTF-8", $zip->getNameIndex($i)));
+ $file_name = str_replace('..', '.',
$zip->getNameIndex($i));
$copy_to = $dir.'/'.$file_name;
if (!is_dir(dirname($copy_to)))
{
@@ -368,23 +433,25 @@
{
$content = scandir($dir);
- $output = array();
foreach($content as $key => $value)
{
$path = realpath($dir.'/'.$value);
if(is_file($path))
{
- unset($output);
- exec('md5sum "'.$path.'" 2>&1',
$output, $ret);
- if ($ret)
+ $pos = strpos($value, '..');
+ if (!$pos === false)
{
- $val_md5sum = '';
- } else {
- $val_md5sum =
trim(strstr($output[0], ' ', true)).' '.$value;
- }
+ $new_path = str_replace('..',
'.', $path);
+ if (rename($path, $new_path))
+ {
+ $value =
str_replace('..', '.', $value);
+ $path = $new_path;
+ }
+ }
+
$results[] = array('file'=>$value,
- 'val_md5sum'=>$val_md5sum,
- 'path_file'=>$path);
+ 'path_absolute'=>$path,
+ 'path_relative'=>'/');
}
}
@@ -397,24 +464,15 @@
$patrones = array('(\\/)', '(\\\\)', '(")');
$sustituciones = array('_', '_', '_');
- $output = array();
foreach($content as $key => $value)
{
$path = realpath($dir.'/'.$value);
if(is_file($path))
{
- unset($output);
- exec('md5sum "'.$path.'" 2>&1',
$output, $ret);
- if ($ret)
- {
- $val_md5sum = '';
- } else {
- $val_md5sum =
trim(strstr($output[0], ' ', true)).' '.$value;
- }
$results[] = array('file'=>$value,
- 'val_md5sum'=>$val_md5sum,
-
'path_file_string'=>preg_replace($patrones, $sustituciones, $path),
- 'path_file'=>$path);
+
'path_string'=>preg_replace($patrones, $sustituciones, $path),
+ 'path_absolute'=>$path,
+ 'path_relative'=>substr($dir,
strlen($this->path_upload_dir)));
}
else if($value != "." && $value != "..")
{
@@ -429,16 +487,9 @@
{
$exceldata =
$this->_getexceldata($_FILES['file']['tmp_name'], false);
$component_files = array();
-
- if ($this->receipt['error'])
- {
- return $this->receipt;
- }
- $patrones = array('(\\/)', '(\\\\)', '(")');
- $sustituciones = array('_', '_', '_');
- $patrones_2 = array('(\\/)', '(")');
- $sustituciones_2 = array('_', '_');
+ $patrones = array('(\\/)', '(")');
+ $sustituciones = array('_', '_');
foreach ($exceldata as $k => $row)
{
if (!$this->_valid_row($row))
@@ -446,16 +497,20 @@
continue;
}
- $path = $row[(count($row)-2)];
$path_file = str_replace('..', '.',
$row[(count($row)-1)]);
+ $path_file = preg_replace($patrones,
$sustituciones, $path_file);
$array_path = explode("\\", $path_file);
+
+ $file_name = $array_path[count($array_path)-1];
+ $path = implode("/", array_slice($array_path,
0, (count($array_path)-1)));
+ $path_string = implode("_", $array_path);
$component_files[$row[0]][] = array(
'name' => $row[1],
'desription' => $row[2],
- 'file' =>
$array_path[count($array_path)-1],
- 'path' => preg_replace($patrones_2,
$sustituciones_2, $path),
- 'path_file_string' =>
preg_replace($patrones, $sustituciones, $path_file),
+ 'file' => $file_name,
+ 'path' => $path,
+ 'path_string' => $path_string,
'row' => ($k + 1)
);
}
@@ -463,43 +518,149 @@
return $component_files;
}
+ private function
_search_relations_with_components_location($relations)
+ {
+ $count_new_relations = 0;
+ $count_relations_existing = 0;
+ foreach ($relations as $k => $files)
+ {
+ if (empty($k))
+ {
+ $component = array('id' =>
$this->location_item_id, 'location_id' =>
$GLOBALS['phpgw']->locations->get_id('property',
'.location.'.count(explode('-', $this->location_code))));
+ }
+ else {
+ $component = $this->_get_component($k,
$this->attrib_name_componentID, $this->location_code);
+ if( empty($component['id']) ||
empty($component['location_id']))
+ {
+ $this->receipt['message'][] =
array('msg' => lang("Component '%1' with location code '%2' does not exist",
$k, $this->location_code));
+ continue;
+ }
+ }
+
+ $files_in_component =
$this->_get_files_by_component($component['id'], $component['location_id']);
+
+ foreach ($files as $file_data)
+ {
+ if (empty($file_data['md5sum']))
+ {
+ continue;
+ }
+
+ if (in_array($file_data['md5sum'],
$files_in_component))
+ {
+ $count_relations_existing++;
+ } else {
+ $count_new_relations++;
+ }
+ }
+ }
+
+ if ($count_relations_existing)
+ {
+ $this->receipt['message'][] = array('msg' =>
lang('%1 relations existing', $count_relations_existing));
+ }
+
+ if ($count_new_relations)
+ {
+ $this->receipt['message'][] = array('msg' =>
lang('%1 new relations to add', $count_new_relations));
+ } else {
+ $this->receipt['message'][] = array('msg' =>
lang('any relation to add'));
+ }
+ }
+
+ private function _search_relations_with_location($relations)
+ {
+ $count_new_relations = 0;
+ $count_relations_existing = 0;
+
+ $component = array('id' => $this->location_item_id,
'location_id' => $GLOBALS['phpgw']->locations->get_id('property',
'.location.'.count(explode('-', $this->location_code))));
+ $files_in_component =
$this->_get_files_by_component($component['id'], $component['location_id']);
+
+ foreach ($relations as $file_data)
+ {
+ if (empty($file_data['md5sum']))
+ {
+ continue;
+ }
+
+ if (in_array($file_data['md5sum'],
$files_in_component))
+ {
+ $count_relations_existing++;
+ } else {
+ $count_new_relations++;
+ }
+ }
+
+ if ($count_relations_existing)
+ {
+ $this->receipt['message'][] = array('msg' =>
lang('%1 relations existing', $count_relations_existing));
+ }
+
+ if ($count_new_relations)
+ {
+ $this->receipt['message'][] = array('msg' =>
lang('%1 new relations to add', $count_new_relations));
+ } else {
+ $this->receipt['message'][] = array('msg' =>
lang('any relation to add'));
+ }
+ }
+
public function preview ()
{
$with_components =
phpgw::get_var('with_components_check');
$uploaded_files = $this->_get_uploaded_files();
-
+
+ if ($this->receipt['error'])
+ {
+ return $this->receipt;
+ }
+
if ($with_components)
{
$relations = $this->get_relations();
$this->_compare_names($relations,
$uploaded_files);
+
$this->_search_relations_with_components_location($relations);
} else {
$relations = array();
$this->_compare_names($relations,
$uploaded_files);
+
$this->_search_relations_with_location($relations);
}
-
+
phpgwapi_cache::session_set('property',
'paths_from_file', $this->paths_from_file);
phpgwapi_cache::session_set('property', 'import_data',
$relations);
- $message['message'][] = array('msg' => lang('%1 files
prepare to copy', count($this->paths_from_file)));
+ $files_in_db = 0;
+ foreach ($this->paths_from_file as $k => $v)
+ {
+ if ($this->_search_file_in_db($k))
+ {
+ $files_in_db++;
+ }
+ }
+
+ if ($files_in_db)
+ {
+ $this->receipt['message'][] = array('msg' =>
lang('%1 files exist in db', $files_in_db));
+ }
+ $this->receipt['message'][] = array('msg' => lang('%1
files prepare to copy', (count($this->paths_from_file) - $files_in_db)));
if (count($this->paths_empty))
{
- $message['error'][] = array('msg' => lang('%1
files not exist in the temporary folder', count($this->paths_empty)));
+ $this->receipt['error'][] = array('msg' =>
lang('%1 files not exist in the temporary folder', count($this->paths_empty)));
foreach($this->paths_empty as $c => $v)
{
- $message['error'][] = array('msg' =>
lang("file not exist: %1", $v));
+ $this->receipt['error'][] = array('msg'
=> lang("file not exist: %1", $v));
}
}
- return $message;
+ return $this->receipt;
}
- public function add_files_components_location($id,
$location_code, $attrib_name_componentID)
+ public function add_files_components_location()
{
@set_time_limit(5 * 60);
-
+
$message = array();
$component_files =
phpgwapi_cache::session_get('property', 'import_data');
@@ -508,7 +669,7 @@
$count_new_relations = 0;
$count_relations_existing = 0;
$count_new_files = 0;
- //$count_files_not_existing = 0;
+ $files_existing = array();
$files_not_existing = array();
foreach ($component_files as $k => $files)
@@ -515,13 +676,13 @@
{
if (empty($k))
{
- $component = array('id' => $id,
'location_id' => $GLOBALS['phpgw']->locations->get_id('property',
'.location.'.count(explode('-', $location_code))));
+ $component = array('id' =>
$this->location_item_id, 'location_id' =>
$GLOBALS['phpgw']->locations->get_id('property',
'.location.'.count(explode('-', $this->location_code))));
}
else {
- $component = $this->_get_component($k,
$attrib_name_componentID, $location_code);
+ $component = $this->_get_component($k,
$this->attrib_name_componentID, $this->location_code);
if( empty($component['id']) ||
empty($component['location_id']))
{
- $message['message'][] =
array('msg' => lang("Component '%1' with location code '%2' does not exist",
$k, $location_code));
+ $message['message'][] =
array('msg' => lang("Component '%1' with location code '%2' does not exist",
$k, $this->location_code));
continue;
}
}
@@ -530,9 +691,10 @@
foreach ($files as $file_data)
{
- if (in_array(str_replace(' ', '_',
$file_data['val_md5sum']), $files_in_component))
+ if (in_array($file_data['md5sum'],
$files_in_component))
{
$count_relations_existing++;
+
$files_existing[$file_data['md5sum']] = $file_data['md5sum'];
continue;
}
@@ -545,21 +707,27 @@
$file_id =
$this->_search_in_last_files_added($file_data);
if (!$file_id)
- {
- if
(!is_file($file_data['path_file']))
+ {
+ $file_id =
$this->_search_file_in_db($file_data['md5sum']);
+ if (!$file_id)
{
-
//$count_files_not_existing++;
-
$files_not_existing[] = ($file_data['path_file']) ? $file_data['path_file'] :
$file_data['path'].'/'.$file_data['file'];
- throw new
Exception();
- }
+ if
(!is_file($file_data['path_absolute']))
+ {
+ $_file
= ($file_data['path_absolute']) ? $file_data['path_absolute'] :
$file_data['path'].'/'.$file_data['file'];
+
$files_not_existing[strtolower($file_data['file'])] = $_file;
+ throw
new Exception();
+ }
- $file_id =
$this->_save_file($file_data);
- if (!$file_id)
- {
- throw new
Exception("failed to copy file: '{$file_data['path_file']}'. Component:
'{$k}'");
- }
-
unlink($file_data['path_file']);
- $count_new_files++;
+ $file_id =
$this->_save_file($file_data);
+ if (!$file_id)
+ {
+ throw
new Exception("failed to copy file: '{$file_data['path_absolute']}'. Component:
'{$k}'");
+ }
+
unlink($file_data['path_absolute']);
+
$count_new_files++;
+ } else {
+
$files_existing[$file_data['md5sum']] = $file_data['md5sum'];
+ }
}
$result =
$this->_save_file_relation($component['id'], $component['location_id'],
$file_id);
@@ -567,6 +735,7 @@
{
$message['error'][] =
array('msg' => "failed to save relation. File: '{$file}'. Component: '{$k}'");
} else {
+
$this->last_files_added[$file_id] = $file_data['md5sum'];
$count_new_relations++;
}
@@ -594,6 +763,9 @@
} else {
$message['message'][] = array('msg' => lang('%1
files copy', $count_new_files));
}
+ if (count($files_existing)){
+ $message['message'][] = array('msg' => lang('%1
files existing in db', count($files_existing)));
+ }
if ($count_new_relations)
{
$message['message'][] = array('msg' => lang('%1
relations saved successfully', $count_new_relations));
@@ -661,16 +833,12 @@
{
$metadata = array();
- //$tmp_file = $file_data['file'];
+ $path_file = $file_data['path_absolute'];
+ $md5sum = $file_data['md5sum'];
- $val_md5sum = $file_data['val_md5sum'];
- $path_file = $file_data['path_file'];
-
- $md5_sum = trim(strstr($val_md5sum, ' ', true));
-
$bofiles = CreateObject('property.bofiles');
- $file_name = str_replace(' ', '_',
trim(strstr($val_md5sum, ' ')));
+ $file_name = str_replace(' ', '_',
trim($file_data['file']));
$to_file = $bofiles->fakebase . '/generic_document/'
.$file_name;
@@ -692,15 +860,13 @@
{
return false;
}
-
- $this->last_files_added[$file_id] = $val_md5sum;
- $this->db->query("UPDATE phpgw_vfs SET
md5_sum='{$md5_sum}'"
+ $this->db->query("UPDATE phpgw_vfs SET
md5_sum='{$md5sum}'"
. " WHERE file_id='{$file_id}'", __LINE__,
__FILE__);
- if (count($this->paths_from_file[$val_md5sum]))
+ if (count($this->paths_from_file[$md5sum]))
{
- $paths =
array_values(array_unique($this->paths_from_file[$val_md5sum]));
+ $paths =
array_values(array_unique($this->paths_from_file[$md5sum]));
} else {
$paths = array();
}
Modified: trunk/property/js/portico/admin_entity.edit_category.js
===================================================================
--- trunk/property/js/portico/admin_entity.edit_category.js 2017-01-25
08:38:31 UTC (rev 16188)
+++ trunk/property/js/portico/admin_entity.edit_category.js 2017-01-25
08:47:46 UTC (rev 16189)
@@ -36,6 +36,7 @@
});
document.form.template_attrib.value = values_tophp;
+ document.form.submit();
}
this.get_template_attributes = function ()
Modified: trunk/property/js/portico/import_components.js
===================================================================
--- trunk/property/js/portico/import_components.js 2017-01-25 08:38:31 UTC
(rev 16188)
+++ trunk/property/js/portico/import_components.js 2017-01-25 08:47:46 UTC
(rev 16189)
@@ -72,27 +72,9 @@
}
});
-
$('#template_list').change( function()
{
- var oArgs = {menuaction:
'property.uiimport_components.get_attributes_from_template'};
- var requestUrl = phpGWLink('index.php', oArgs, true);
-
- var data = {"category_template": $(this).val()};
- JqueryPortico.execute_ajax(requestUrl,
- function(result){
- var $el = $("#attribute_name_component_id");
- $el.empty();
- $.each(result, function(key, value) {
- if (value.selected)
- {
- $el.append($("<option
selected></option>").attr("value", value.id).text(value.name));
- } else {
-
$el.append($("<option></option>").attr("value", value.id).text(value.name));
- }
- });
- }, data, "GET", "json"
- );
+ fill_template_attributes('');
});
$('#relations_step_1').on('click', function ()
@@ -120,6 +102,12 @@
return false;
}
+ if ($('#attribute_name_component_id').val() === '')
+ {
+ alert('Choose attribute name for Component ID');
+ return false;
+ }
+
if ($('input:radio[name=compressed_file_check]:checked').val()
== 1 && $('#compressed_file_name').val() == '')
{
alert('Enter the name of the compressed file');
@@ -144,7 +132,7 @@
{
return false;
}
- //form_data.append('attribute_name_component_id',
$('#attribute_name_component_id').val());
+ form_data.append('attribute_name_component_id',
$('#attribute_name_component_id').val());
form_data.append('location_code', $('#location_code').val());
form_data.append('location_item_id',
$('#location_item_id').val());
form_data.append('compressed_file_check',
$('input:radio[name=compressed_file_check]:checked').val());
@@ -196,6 +184,12 @@
return false;
}
+ if ($('#attribute_name_component_id').val() === '')
+ {
+ alert('Choose attribute name for Component ID');
+ return false;
+ }
+
if (isSendingData())
{
return false;
@@ -663,9 +657,8 @@
if (result.template_id)
{
$('#template_list').val(result.template_id);
+
fill_template_attributes(result.attrib_name_componentID);
}
-
$('#attribute_name_component_id').val(result.attrib_name_componentID);
-
}, data, "GET", "JSON"
);
});
@@ -672,6 +665,28 @@
});
+function fill_template_attributes (selected_attribute)
+{
+ var oArgs = {menuaction:
'property.uiimport_components.get_attributes_from_template'};
+ var requestUrl = phpGWLink('index.php', oArgs, true);
+
+ var data = {"category_template": $("#template_list").val(),
"selected_attribute": selected_attribute};
+ JqueryPortico.execute_ajax(requestUrl,
+ function(result){
+ var $el = $("#attribute_name_component_id");
+ $el.empty();
+ $.each(result, function(key, value) {
+ if (value.selected)
+ {
+ $el.append($("<option
selected></option>").attr("value", value.id).text(value.name));
+ } else {
+
$el.append($("<option></option>").attr("value", value.id).text(value.name));
+ }
+ });
+ }, data, "GET", "json"
+ );
+}
+
function valid_new_attribute (code)
{
if ($('#name_' + code).val() == '')
Modified: trunk/property/templates/base/admin_entity.xsl
===================================================================
--- trunk/property/templates/base/admin_entity.xsl 2017-01-25 08:38:31 UTC
(rev 16188)
+++ trunk/property/templates/base/admin_entity.xsl 2017-01-25 08:47:46 UTC
(rev 16189)
@@ -437,6 +437,7 @@
<script type="text/javascript">
self.name="first_Window";
<xsl:value-of select="lookup_functions"/>
+ var base_java_url = <xsl:value-of select="base_java_url"/>;
</script>
<dl>
@@ -915,7 +916,7 @@
</xsl:choose>
<tr height="50">
<td>
- <input type="submit"
class="pure-button pure-button-primary" name="values[save]" value="{lang_save}">
+ <input type="button"
class="pure-button pure-button-primary" name="values[save]" value="{lang_save}"
onClick="onActionsClick();">
<xsl:attribute
name="title">
<xsl:value-of select="php:function('lang', 'save')"/>
</xsl:attribute>
Modified: trunk/property/templates/base/multi_upload_file.xsl
===================================================================
--- trunk/property/templates/base/multi_upload_file.xsl 2017-01-25 08:38:31 UTC
(rev 16188)
+++ trunk/property/templates/base/multi_upload_file.xsl 2017-01-25 08:47:46 UTC
(rev 16189)
@@ -12,17 +12,20 @@
<div class="fileupload-buttons">
<!-- The fileinput-button span is used to style
the file input field as button -->
<span class="fileinput-button pure-button">
- <span>Add files...</span>
+ <span><xsl:value-of
select="php:function('lang', 'Add files')"/>...</span>
<input type="file" id="files"
name="files[]" multiple=""/>
</span>
- <button type="submit" class="start
pure-button">Start upload</button>
- <button type="reset" class="cancel
pure-button">Cancel upload</button>
- <button type="button" class="delete
pure-button">Delete</button>
+ <button type="submit" class="start
pure-button"><xsl:value-of select="php:function('lang', 'Start
upload')"/></button>
+ <button type="reset" class="cancel
pure-button"><xsl:value-of select="php:function('lang', 'Cancel
upload')"/></button>
+ <button type="button" class="delete
pure-button"><xsl:value-of select="php:function('lang', 'Delete')"/></button>
<input type="checkbox" class="toggle"/>
<!-- The global file processing state -->
<span class="fileupload-process"></span>
</div>
- <div class="fileupload-progress fade"
style="display:none">
+ <div class="fileupload-count">
+ <xsl:value-of select="php:function('lang',
'Number files')"/>: <span id="files-count"></span>
+ </div>
+ <div class="fileupload-progress fade"
style="display:none">
<!-- The global progress bar -->
<div class="progress" role="progressbar"
aria-valuemin="0" aria-valuemax="100"></div>
<!-- The extended global progress state -->
@@ -96,7 +99,8 @@
//xhrFields: {withCredentials: true},
url: '<xsl:value-of
select="multi_upload_action"/>',
limitConcurrentUploads: 4,
- maxChunkSize: 838855500
+ // maxChunkSize: 838855500
+ maxChunkSize: 8388000
//acceptFileTypes: /(\.|\/)(png|pdf)$/i
});
@@ -111,10 +115,19 @@
);
$('#multi_upload_file')
- .bind('fileuploadcompleted', function (e, data)
{
- console.log(data.result.num_files);
+ .bind('fileuploadcompleted', function (e, data)
{
+ $( "#files-count" ).html(data.result.num_files);
});
-
+
+ $('#multi_upload_file')
+ .bind('fileuploaddestroyed', function (e, data)
{
+ var n = 0;
+ $( ".template-download" ).each(function( i ) {
+ n ++;
+ });
+ $("#files-count").html(n);
+ });
+
// Load existing files:
$('#multi_upload_file').addClass('fileupload-processing');
$.ajax({
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Fmsystem-commits] [16189] Backport diff from Syncromind to trunk,
sigurdne <=