[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Fmsystem-commits] [15748] Backport 15258:15747 from Syncromind
From: |
sigurdne |
Subject: |
[Fmsystem-commits] [15748] Backport 15258:15747 from Syncromind |
Date: |
Wed, 28 Sep 2016 10:26:36 +0000 (UTC) |
Revision: 15748
http://svn.sv.gnu.org/viewvc/?view=rev&root=fmsystem&revision=15748
Author: sigurdne
Date: 2016-09-28 10:26:36 +0000 (Wed, 28 Sep 2016)
Log Message:
-----------
Backport 15258:15747 from Syncromind
Modified Paths:
--------------
trunk/activitycalendar/templates/base/css/base.css
trunk/booking/js/booking/schedule.js
trunk/booking/templates/base/css/base.css
trunk/booking/templates/base/season_wtemplate.xsl
trunk/bookingfrontend/css/bookingfrontend.css
trunk/bookingfrontend/js/bookingfrontend/schedule.js
trunk/phpgwapi/inc/class.jquery.inc.php
trunk/phpgwapi/js/jquery/common.js
trunk/property/inc/class.menu.inc.php
trunk/property/inc/class.uiimport.inc.php
trunk/registration/templates/base/css/base.css
trunk/rental/inc/class.boapplication.inc.php
trunk/rental/inc/class.menu.inc.php
trunk/rental/inc/class.soapplication.inc.php
trunk/rental/inc/class.socomposite.inc.php
trunk/rental/inc/class.socontract.inc.php
trunk/rental/inc/class.uiapplication.inc.php
trunk/rental/inc/class.uicomposite.inc.php
trunk/rental/inc/class.uicontract.inc.php
trunk/rental/inc/model/class.application.inc.php
trunk/rental/js/rental/application.edit.js
trunk/rental/js/rental/composite.edit.js
trunk/rental/js/rental/composite.view.js
trunk/rental/templates/base/application.xsl
trunk/rental/templates/base/composite.xsl
trunk/rental/templates/base/css/base.css
Added Paths:
-----------
trunk/phpgwapi/js/jquery/file-upload/
trunk/property/inc/class.uiimport_components.inc.php
trunk/property/inc/import/UploadHandler.php
trunk/property/inc/import/class.import_component_files.inc.php
trunk/property/inc/import/class.import_components.inc.php
trunk/property/inc/import/class.import_entity_categories.inc.php
trunk/property/inc/import/class.import_update_components.inc.php
trunk/property/js/portico/import_components.js
trunk/property/templates/base/images/ajax-loader.gif
trunk/property/templates/base/import_components.xsl
trunk/rental/js/rental/schedule.js
trunk/rental/templates/base/rental_schedule.xsl
trunk/rental/templates/base/schedule.xsl
Property Changed:
----------------
trunk/
trunk/booking/
trunk/bookingfrontend/
Property changes on: trunk
___________________________________________________________________
Modified: svn:mergeinfo
- /branches/dev-syncromind:13653
/branches/dev-syncromind-2:14937-15027,15165-15215,15223-15228,15230-15243,15245-15250,15254-15257
/branches/stavangerkommune:12743-12875,12986
+ /branches/dev-syncromind:13653
/branches/dev-syncromind-2:14933-15747
/branches/stavangerkommune:12743-12875,12986
Modified: trunk/activitycalendar/templates/base/css/base.css
===================================================================
--- trunk/activitycalendar/templates/base/css/base.css 2016-09-28 08:47:07 UTC
(rev 15747)
+++ trunk/activitycalendar/templates/base/css/base.css 2016-09-28 10:26:36 UTC
(rev 15748)
@@ -265,7 +265,7 @@
#week-selector li { display: inline; padding-right: .5em;}
#schedule_container tr td { border-top: 1px solid #ccc; background: white;
white-space: nowrap; }
-#schedule_container tr td:first-child { background: #eee; }
+#schedule_container tbody tr th:first-child { background: #eee; }
#schedule_container tr.time td { border-top: 1px solid #444;}
#schedule_container .color1 { background: #ccf;}
#schedule_container .color2 { background: #cfc;}
Property changes on: trunk/booking
___________________________________________________________________
Modified: svn:mergeinfo
- /branches/stavangerkommune/booking:9468-12740,12743-12875,12986
+ /branches/dev-syncromind-2/booking:14933-15747
/branches/stavangerkommune/booking:9468-12740,12743-12875,12986
Modified: trunk/booking/js/booking/schedule.js
===================================================================
--- trunk/booking/js/booking/schedule.js 2016-09-28 08:47:07 UTC (rev
15747)
+++ trunk/booking/js/booking/schedule.js 2016-09-28 10:26:36 UTC (rev
15748)
@@ -1,4 +1,5 @@
var schedule = new Array();
+schedule.params = {};
schedule.renderSchedule = function (container, url, date, colFormatter,
includeResource, classTable)
{
@@ -11,6 +12,7 @@
// container.innerHTML = '';
var datestr = date.getFullYear() + '-' + (date.getMonth() + 1) + '-' +
date.getDate();
url += '&date=' + datestr;
+ schedule.params.date = datestr;
var detected_lang = navigator.language || navigator.userLanguage;
var lang = {};
@@ -46,7 +48,7 @@
}
var colDefs = [
- {key: 'time', label: date.getFullYear() + '<br/>' +
lang['LBL_TIME']}];
+ {key: 'time', label: date.getFullYear() + '<br/>' +
lang['LBL_TIME'], type: 'th'}];
if (includeResource)
{
colDefs.push({key: 'resource', label: lang['LBL_RESOURCE'],
formatter: 'scheduleResourceColumn'});
@@ -62,8 +64,10 @@
colDefs.push({key: keys[x], label: lang['WEEKDAYS_FULL'][x] +
'<br>' + lang['MONTHS_LONG'][d.getMonth()] + ' ' + d.getDate(), formatter:
colFormatter, date: d, day: d.getDate()});
}
var r = [{n: 'ResultSet'}, {n: 'Result'}];
+ var params = (schedule.params) ? schedule.params : new Array();
+
// createta d u c r cl
- createTableSchedule(container, url, colDefs, r, classTable, datestr);
+ createTableSchedule(container, url, colDefs, r, classTable, params);
};
Modified: trunk/booking/templates/base/css/base.css
===================================================================
--- trunk/booking/templates/base/css/base.css 2016-09-28 08:47:07 UTC (rev
15747)
+++ trunk/booking/templates/base/css/base.css 2016-09-28 10:26:36 UTC (rev
15748)
@@ -180,7 +180,7 @@
#week-selector li { display: inline; padding-right: .5em;}
#schedule_container tr td { border-top: 1px solid #ccc; background: white;
white-space: nowrap; }
-#schedule_container tr td:first-child { background: #eee; }
+#schedule_container tbody tr th:first-child { background: #eee; }
#schedule_container tr.time td { border-top: 1px solid #444;}
#schedule_container .color1 { background-color: #ccccff;}
#schedule_container .color2 { background-color: #ccffcc;}
Modified: trunk/booking/templates/base/season_wtemplate.xsl
===================================================================
--- trunk/booking/templates/base/season_wtemplate.xsl 2016-09-28 08:47:07 UTC
(rev 15747)
+++ trunk/booking/templates/base/season_wtemplate.xsl 2016-09-28 10:26:36 UTC
(rev 15748)
@@ -96,7 +96,7 @@
var colDefs = [];
$(window).load(function() {
colDefs = [
- {key: 'time', label: '<xsl:value-of
select="php:function('lang', 'Time')" />'},
+ {key: 'time', label: '<xsl:value-of
select="php:function('lang', 'Time')" />', type: 'th'},
{key: 'resource', label: '<xsl:value-of
select="php:function('lang', 'Resources')" />', formatter:
'scheduleResourceColumn'},
{key: '1', label: '<xsl:value-of select="php:function('lang',
'Monday')" />', formatter: 'seasonDateColumn'},
{key: '2', label: '<xsl:value-of select="php:function('lang',
'Tuesday')" />', formatter: 'seasonDateColumn'},
Property changes on: trunk/bookingfrontend
___________________________________________________________________
Modified: svn:mergeinfo
- /branches/stavangerkommune/bookingfrontend:9468-12740,12986
+ /branches/dev-syncromind-2/bookingfrontend:14933-15747
/branches/stavangerkommune/bookingfrontend:9468-12740,12986
Modified: trunk/bookingfrontend/css/bookingfrontend.css
===================================================================
--- trunk/bookingfrontend/css/bookingfrontend.css 2016-09-28 08:47:07 UTC
(rev 15747)
+++ trunk/bookingfrontend/css/bookingfrontend.css 2016-09-28 10:26:36 UTC
(rev 15748)
@@ -407,7 +407,7 @@
border-top: 1px solid #ccc;
white-space: nowrap;
}
-#schedule_container tr td:first-child {
+#schedule_container tbody tr th:first-child {
background: #eee none repeat scroll 0 0;
}
#schedule_container tr.time td {
Modified: trunk/bookingfrontend/js/bookingfrontend/schedule.js
===================================================================
--- trunk/bookingfrontend/js/bookingfrontend/schedule.js 2016-09-28
08:47:07 UTC (rev 15747)
+++ trunk/bookingfrontend/js/bookingfrontend/schedule.js 2016-09-28
10:26:36 UTC (rev 15748)
@@ -1,4 +1,5 @@
var schedule = new Array();
+schedule.params = {};
schedule.renderSchedule = function (container, url, date, colFormatter,
includeResource, classTable)
{
@@ -9,6 +10,7 @@
}
var datestr = date.getFullYear() + '-' + (date.getMonth() + 1) + '-' +
date.getDate();
url += '&date=' + datestr;
+ schedule.params.date = datestr;
var detected_lang = navigator.language || navigator.userLanguage;
var lang = {};
@@ -44,7 +46,8 @@
}
var colDefs = [
- {key: 'time', label: date.getFullYear() + '<br/>' +
lang['LBL_TIME']}];
+ {key: 'time', label: date.getFullYear() + '<br/>' +
lang['LBL_TIME'], type: 'th'}
+ ];
if (includeResource)
{
colDefs.push({key: 'resource', label: lang['LBL_RESOURCE'],
formatter: 'scheduleResourceColumn'});
@@ -60,8 +63,10 @@
colDefs.push({key: keys[x], label: lang['WEEKDAYS_FULL'][x] +
'<br>' + lang['MONTHS_LONG'][d.getMonth()] + ' ' + d.getDate(), formatter:
colFormatter, date: d, day: d.getDate()});
}
var r = [{n: 'ResultSet'}, {n: 'Result'}];
+ var params = (schedule.params) ? schedule.params : new Array();
+
// createta d u c r cl
- createTableSchedule(container, url, colDefs, r, classTable, datestr);
+ createTableSchedule(container, url, colDefs, r, classTable, params);
};
Modified: trunk/phpgwapi/inc/class.jquery.inc.php
===================================================================
--- trunk/phpgwapi/inc/class.jquery.inc.php 2016-09-28 08:47:07 UTC (rev
15747)
+++ trunk/phpgwapi/inc/class.jquery.inc.php 2016-09-28 10:26:36 UTC (rev
15748)
@@ -182,7 +182,24 @@
);
$GLOBALS['phpgw']->css->add_external_file("phpgwapi/js/contextMenu/jquery.contextMenu.min.css");
break;
-
+
+ case 'file-upload':
+ $load = array
+ (
+ "js/{$_jquery_core}{$_type}",
+ "js/{$_jquery_ui}{$_type}",
+ "file-upload/js/tmpl{$_type}",
+
"file-upload/js/jquery.fileupload",
+
"file-upload/js/jquery.fileupload-process",
+
"file-upload/js/jquery.fileupload-validate",
+
"file-upload/js/jquery.fileupload-ui",
+
"file-upload/js/jquery.fileupload-jquery-ui",
+ );
+
$GLOBALS['phpgw']->css->add_external_file("phpgwapi/js/jquery/file-upload/css/jquery.fileupload.css");
+
$GLOBALS['phpgw']->css->add_external_file("phpgwapi/js/jquery/file-upload/css/jquery.fileupload-custom.css");
+
$GLOBALS['phpgw']->css->add_external_file("phpgwapi/js/jquery/file-upload/css/jquery.fileupload-ui.css");
+ break;
+
default:
$err = "Unsupported jQuery widget '%1'
supplied to phpgwapi_jquery::load_widget()";
trigger_error(lang($err, $widget),
E_USER_WARNING);
@@ -467,4 +484,133 @@
JS;
$GLOBALS['phpgw']->js->add_code('', $js);
}
+
+ public static function form_file_upload_generate( $action )
+ {
+ self::load_widget('file-upload');
+ $output = <<<HTML
+ <form id="fileupload" action="{$action}" method="POST"
enctype="multipart/form-data">
+ <!-- The fileupload-buttonbar contains buttons
to add/delete files and start/cancel the upload -->
+ <div class="fileupload-buttonbar">
+ <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>
+ <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>
+ <input type="checkbox"
class="toggle">
+ <!-- The global file processing
state -->
+ <span
class="fileupload-process"></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 -->
+ <div
class="progress-extended"> </div>
+ </div>
+ </div>
+ <!-- The table listing the files available for
upload/download -->
+ <div style="position: relative; overflow: auto;
max-height: 50vh; width: 100%;">
+ <div class="presentation files"
style="display: inline-table;"></div>
+ </div>
+
+ </form>
+
+ <!-- The template to display files available for upload
-->
+ <script id="template-upload" type="text/x-tmpl">
+ {% for (var i=0, file; file=o.files[i]; i++) { %}
+ <div class="template-upload fade table-row">
+ <div class="table-cell">
+ <div
class="name">{%=file.name%}</div>
+ <div class="error"></div>
+ </div>
+ <div class="table-cell">
+ <div
class="size">Processing...</div>
+ </div>
+ <div class="table-cell">
+ <div class="progress"
style="width: 100px;"></div>
+ </div>
+ <div class="table-cell">
+ {% if (!i &&
!o.options.autoUpload) { %}
+ <button class="start
pure-button" disabled>Start</button>
+ {% } %}
+ {% if (!i) { %}
+ <button class="cancel
pure-button">Cancel</button>
+ {% } %}
+ </div>
+ </div>
+ {% } %}
+ </script>
+ <!-- The template to display files available for
download -->
+ <script id="template-download" type="text/x-tmpl">
+ {% for (var i=0, file; file=o.files[i]; i++) { %}
+ <div class="template-download fade table-row">
+ <div class="table-cell">
+ <div class="name">
+ <!--<a
href="{%=file.url%}" title="{%=file.name%}" download="{%=file.name%}"
{%=file.thumbnailUrl?'data-gallery':''%}>{%=file.name%}</a>-->
+ {%=file.name%}
+ </div>
+ {% if (file.error) { %} <div
class="error">Error: {%=file.error%} </div>{% } %}
+ </div>
+ <div class="table-cell">
+ <div
class="size">{%=o.formatFileSize(file.size)%}</div>
+ </div>
+ <div class="table-cell">
+ <button class="delete
pure-button" data-type="{%=file.deleteType%}" data-url="{%=file.deleteUrl%}"{%
if (file.deleteWithCredentials) { %}
data-xhr-fields='{"withCredentials":true}'{% } %}>Delete</button>
+ <input type="checkbox"
name="delete" value="1" class="toggle">
+ </div>
+ </div>
+ {% } %}
+ </script>
+HTML;
+
+ $js = <<<JS
+
+ $(function () {
+ 'use strict';
+
+ // Initialize the jQuery File Upload widget:
+ $('#fileupload').fileupload({
+ // Uncomment the following to send cross-domain
cookies:
+ //xhrFields: {withCredentials: true},
+ url: '{$action}',
+ limitConcurrentUploads: 4,
+ //acceptFileTypes: /(\.|\/)(png|pdf)$/i
+ });
+
+ // Enable iframe cross-domain access via redirect
option:
+ $('#fileupload').fileupload(
+ 'option',
+ 'redirect',
+ window.location.href.replace(
+ /\/[^\/]*$/,
+ '/cors/result.html?%s'
+ )
+ );
+
+ // Load existing files:
+ $('#fileupload').addClass('fileupload-processing');
+ $.ajax({
+ // Uncomment the following to send cross-domain
cookies:
+ //xhrFields: {withCredentials: true},
+ url: $('#fileupload').fileupload('option',
'url'),
+ dataType: 'json',
+ context: $('#fileupload')[0]
+ }).always(function () {
+ $(this).removeClass('fileupload-processing');
+ }).done(function (result) {
+ $(this).fileupload('option', 'done')
+ .call(this, $.Event('done'), {result:
result});
+ });
+
+ });
+JS;
+ $GLOBALS['phpgw']->js->add_code('', $js);
+
+ return $output;
+ }
+
}
\ No newline at end of file
Modified: trunk/phpgwapi/js/jquery/common.js
===================================================================
--- trunk/phpgwapi/js/jquery/common.js 2016-09-28 08:47:07 UTC (rev 15747)
+++ trunk/phpgwapi/js/jquery/common.js 2016-09-28 10:26:36 UTC (rev 15748)
@@ -181,10 +181,10 @@
};
//JqueryPortico.formatCheckEvent = function(key, oData) {
-//
-// var hidden = '';
-//
-// return hidden + "<center><input type=\"checkbox\" class=\"mychecks\"
name=\"values[events]["+oData['id']+"_"+oData['schedule_time']+"]\"
value=\""+oData['id']+"\"/></center>";
+//
+// var hidden = '';
+//
+// return hidden + "<center><input type=\"checkbox\"
class=\"mychecks\"
name=\"values[events]["+oData['id']+"_"+oData['schedule_time']+"]\"
value=\""+oData['id']+"\"/></center>";
//}
JqueryPortico.formatCheckUis_agremment = function (key, oData)
@@ -604,6 +604,11 @@
url: requestUrl,
success: function (result)
{
+ if (typeof (result.sessionExpired) !== 'undefined')
+ {
+ alert('sessionExpired - please log in');
+ return;
+ }
callback(result);
}
});
@@ -1273,26 +1278,14 @@
}
-function createTableSchedule(d, u, c, r, cl, dt)
+function createTableSchedule (d, u, c, r, cl, a, p, t)
{
-// var detected_lang = navigator.language || navigator.userLanguage;
- var lang = {};
-
-// if(detected_lang == 'no' || detected_lang == 'nn' || detected_lang ==
'nb' ||detected_lang == 'nb-no' || detected_lang == 'no-no' || detected_lang ==
'nn-no')
- if (window.navigator.language != "en")
- {
- lang = {free: 'Ledig'};
- }
- else
- {
- lang = {free: 'free'};
- }
-
var container = document.getElementById(d);
+ var container_toolbar = document.createElement('div');
var xtable = document.createElement('table');
var tableHead = document.createElement('thead');
var tableHeadTr = document.createElement('tr');
- var date = (dt) ? dt : "";
+ var date = (a) ? (a.date) ? a.date : "" : "";
restartColors();
r = (r) ? r : 'data';
@@ -1310,6 +1303,8 @@
tableHead.appendChild(tableHeadTr);
xtable.appendChild(tableHead);
+ var key = c[0].key;
+
var tableBody = document.createElement('tbody');
var tableBodyTr = document.createElement('tr');
var tableBodyTrTd = document.createElement('td');
@@ -1320,9 +1315,10 @@
xtable.appendChild(tableBody);
container.innerHTML = "";
+ container.appendChild(container_toolbar);
container.appendChild(xtable);
- $.get(u, function (data)
+ $.post(u, a, function (data)
{
var selected = new Array();
if (typeof (r) == 'object')
@@ -1361,9 +1357,10 @@
$.each(c, function (ic, vc)
{
var k = vc.key;
- var colorCell = "";
- var tableBodyTrTdType = (k == "time") ?
"th" : "td";
+// var tableBodyTrTdType = (k == key) ?
"th" : "td";
+ var tableBodyTrTdType = (vc['type']) ?
(vc['type'] == "th") ? "th" : "td" : "td";
+
var tableBodyTrTd =
document.createElement(tableBodyTrTdType);
var classes = "";
@@ -1371,99 +1368,42 @@
if (vc['formatter'])
{
- if (vc['formatter'] ==
"scheduleResourceColumn")
+ //var dataFormat = {};
+ var dataFormat =
setFormatter(vc['formatter'], vd, vc, date)
+
+ if (dataFormat['text'])
{
- if (vd[k])
+ tableBodyTrTdText =
dataFormat['text'];
+ }
+
+ if (dataFormat['classes'])
+ {
+ classes += " " +
dataFormat['classes'];
+ }
+
+ if (dataFormat['trAttributes'])
+ {
+
$.each(dataFormat['trAttributes'], function (i, v)
{
-
tableBodyTr.setAttribute('resource', vd['resource_id']);
- }
- var resourceLink =
(date) ? vd['resource_link'] + "#date=" + date : vd['resource_link'];
- tableBodyTrTdText =
(vd[k]) ? formatGenericLink(vd['resource'], resourceLink) : "";
+
tableBodyTr.setAttribute(v['attribute'], v['value']);
+ });
}
- else
+
+ if (dataFormat['trFunction'])
{
- if (vd[k])
+
$.each(dataFormat['trFunction'], function (i, v)
{
- var id =
vd[k]['id'];
- var name =
(vd[k]['shortname']) ? formatScheduleShorten(vd[k]['shortname'], 9) :
formatScheduleShorten(vd[k]['name'], 9);
- var type =
vd[k]['type'];
- if
(vc['formatter'] == "seasonDateColumn")
- {
-
tableBodyTrTdText = name;
-
tableBodyTrTd.addEventListener('click', function ()
- {
-
schedule.newAllocationForm({'id': vd[k]['id']})
- });
- }
- if
(vc['formatter'] == "scheduleDateColumn")
- {
-
tableBodyTrTdText = formatGenericLink(name, null);
- }
- if
(vc['formatter'] == "backendScheduleDateColumn")
- {
- var
conflicts = new Array();
- if
(vd[k]['conflicts'])
- {
-
if (vd[k]['conflicts'].length > 0)
-
{
-
conflicts = vd[k]['conflicts'];
-
}
- }
-
tableBodyTrTdText = formatBackendScheduleDateColumn(id, name, type, conflicts);
- classes
+= " " + type;
- }
- if
(vc['formatter'] == "frontendScheduleDateColumn")
- {
- if
(vd[k]['is_public'] == 0)
- {
-
name = formatScheduleShorten('Privat arr.', 9);
- }
-
tableBodyTrTdText = name;
- classes
+= " cellInfo";
- classes
+= " " + type;
-
tableBodyTrTd.addEventListener('click', function ()
- {
-
schedule.showInfo(vd[k]['info_url'], tableBodyTr.getAttribute('resource'))
- },
false);
- }
- colorCell =
formatScheduleCellDateColumn(name, type);
- classes += " "
+ colorCell;
-
tableBodyTrTd.setAttribute('class', classes);
- }
- else
- {
-
tableBodyTrTdText = lang.free;
- classes += "
free";
-
tableBodyTrTd.setAttribute('class', classes);
- if
(vc['formatter'] == "frontendScheduleDateColumn")
- {
-
tableBodyTrTd.addEventListener('click', function ()
- {
-
schedule.newApplicationForm(vc['date'], vd['_from'], vd['_to'],
tableBodyTr.getAttribute('resource'))
- });
- }
- if
(vc['formatter'] == "backendScheduleDateColumn")
- {
-
tableBodyTrTd.addEventListener('click', function ()
- {
-
schedule.newApplicationForm(vc['date'], vd['_from'], vd['_to'])
- });
- }
- if
(vc['formatter'] == "seasonDateColumn")
- {
-
tableBodyTrTd.addEventListener('click', function ()
- {
-
schedule.newAllocationForm({'_from': vd['_from'], '_to': vd['_to'], 'wday':
vc['key']})
- });
- }
- }
+
tableBodyTrTd.addEventListener(v['event'], v['callFunction'], false);
+ });
}
+
+
tableBodyTrTd.setAttribute('class', classes);
}
else
{
- tableBodyTrTdText = (vd[k]) ?
vd[k] : "";
+ tableBodyTrTdText = (vd[k]) ?
(vc['value']) ? vd[k][vc['value']] : (vd[k]) : "";
}
- if (k == "time")
+ if (k == key)
{
borderTop = (vd[k]) ? "2" : "1";
}
@@ -1482,10 +1422,517 @@
});
tableBody.appendChild(tableBodyTr);
});
+
+ if (p)
+ {
+ var start = a.start;
+ var total =
data['ResultSet'].totalResultsAvailable;
+ var n_objects = a.length;
+ start = (start > total) ? 0 : start;
+
+ var pages = Math.floor(total / n_objects);
+ var res = total % n_objects;
+ var page = (start == 0) ? 1 : (start /
n_objects) + 1;
+
+ pages = (res > 0) ? pages+1 : pages;
+ pages = (pages == 0) ? pages+1 : pages;
+
+ var paginator = createPaginatorSchedule(pages,
page);
+ container.appendChild(paginator);
+
+ var input_start =
document.createElement('input');
+ input_start.setAttribute('type', 'hidden');
+ input_start.setAttribute('name', 'start_index');
+ input_start.setAttribute('id', 'start_index');
+ input_start.value = start;
+ container.appendChild(input_start);
+ }
+
+ if (t)
+ {
+ var toolbar = eval(t + "()");
+ container_toolbar.appendChild(toolbar);
+// container.insertBefore(toolbar, xtable);
+ }
}
});
}
+// p -> n pages
+// a -> current page
+function createPaginatorSchedule (p, a)
+{
+ var max = 7;
+ var m = 4;
+
+ var ini = 1;
+ var end = p;
+
+ var buttons = new Array();
+ var n_button = "";
+ var old_button = "";
+
+ for (i = ini; i <= end; i++)
+ {
+ if (i == ini)
+ {
+ n_button = i;
+ }
+ else if ( (a - ini < m ) && (i <= ini + m) )
+ {
+ n_button = i;
+ }
+ else if ( (i >= a - 1) && (i <= a + 1) )
+ {
+ n_button = i;
+ }
+ else if ( (end - a < m ) && (i >= end - m) )
+ {
+ n_button = i;
+ }
+ else if (i == end)
+ {
+ n_button = i;
+ }
+ else
+ {
+ n_button = "...";
+ }
+ if (n_button != old_button)
+ {
+ buttons.push(n_button);
+ old_button = n_button;
+ }
+ }
+
+ var container = document.createElement('div');
+ container.classList.add('schedule_paginate');
+ container.id = "schedule-container_paginate";
+
+ var paginatorPrevButton = document.createElement('a');
+ var paginatorNextButton = document.createElement('a');
+
+ paginatorPrevButton.classList.add('paginate_button', 'previous');
+ paginatorNextButton.classList.add('paginate_button', 'next');
+
+ paginatorPrevButton.innerHTML = "Prev";
+ paginatorNextButton.innerHTML = "Next";
+
+ if (a > 1)
+ {
+ paginatorPrevButton.dataset.page = (a - 1);
+ }
+ else
+ {
+ paginatorPrevButton.classList.add('disabled');
+ }
+ if (a < p)
+ {
+ paginatorNextButton.dataset.page = (a + 1);
+ }
+ else
+ {
+ paginatorNextButton.classList.add('disabled');
+ }
+
+ container.appendChild(paginatorPrevButton);
+ var button_class = "paginate_button";
+ $.each(buttons, function (i, v)
+ {
+ button_class = "paginate_button"
+ var button = document.createElement('span');
+ if (v == "...")
+ {
+ button_class = 'ellipsis';
+ }
+ button.classList.add(button_class);
+ button.dataset.page = v;
+ if (v == a)
+ {
+ button.classList.add('current');
+ }
+ button.innerHTML = v;
+ container.appendChild(button);
+ });
+ container.appendChild(paginatorNextButton);
+
+ return container;
+}
+
+function setFormatter (callFunc, data, col, date)
+{
+ return eval(callFunc+'(data,col,date)');
+}
+
+function scheduleResourceColumn (data, col, date)
+{
+ var text = "";
+ var classes = "";
+ var trAttributes = [];
+ var trFunction = [];
+
+ var k = col.key;
+
+ if (data[k])
+ {
+ trAttributes.push( {attribute: 'resource', value:
data['resource_id']} );
+ }
+
+ var resourceLink = (date) ? data['resource_link'] + "#date=" + date :
data['resource_link'];
+ text = (data[k]) ? formatGenericLink(data['resource'], resourceLink) :
"";
+
+ var data_return = {
+ text: text,
+ classes: classes,
+ trAttributes: trAttributes,
+ trFunction: trFunction
+ }
+
+ return data_return;
+}
+
+function seasonDateColumn (data, col, date)
+{
+ var text = "";
+ var classes = "";
+ var trAttributes = [];
+ var trFunction = [];
+
+ var k = col.key;
+
+ if (data[k])
+ {
+ var id = data[k]['id'];
+ var name = (data[k]['shortname']) ?
formatScheduleShorten(data[k]['shortname'], 9) :
formatScheduleShorten(data[k]['name'], 9);
+ var type = data[k]['type'];
+ var colorCell = formatScheduleCellDateColumn(name, type);
+
+ text = name;
+ classes = colorCell;
+ trFunction.push(
+ {
+ event: 'click',
+ callFunction: function () {
+// schedule.newAllocationForm({id:
data[k]['id']});
+ schedule.newAllocationForm({id: id});
+ }
+ }
+ );
+ }
+ else
+ {
+ text = "free";
+ classes = "free";
+ trFunction.push(
+ {
+ event: 'click',
+ callFunction: function () {
+ schedule.newAllocationForm({'_from':
data['_from'], '_to': data['_to'], 'wday': col['key']});
+ }
+ }
+ );
+ }
+
+ var data_return = {
+ text: text,
+ classes: classes,
+ trAttributes: trAttributes,
+ trFunction: trFunction
+ }
+
+ return data_return;
+}
+
+function scheduleDateColumn (data, col, date)
+{
+ var text = "";
+ var classes = "";
+ var trAttributes = [];
+ var trFunction = [];
+
+ var k = col.key;
+
+ if (data[k])
+ {
+ var name = (data[k]['shortname']) ?
formatScheduleShorten(data[k]['shortname'], 9) :
formatScheduleShorten(data[k]['name'], 9);
+ var type = data[k]['type'];
+ var colorCell = formatScheduleCellDateColumn(name, type);
+
+ text = formatGenericLink(name, null);
+ classes = colorCell;
+ }
+
+ var data_return = {
+ text: text,
+ classes: classes,
+ trAttributes: trAttributes,
+ trFunction: trFunction
+ }
+
+ return data_return;
+}
+
+function backendScheduleDateColumn (data, col, date)
+{
+ var text = "";
+ var classes = "";
+ var trAttributes = [];
+ var trFunction = [];
+
+ var k = col.key;
+
+ if (data[k])
+ {
+ var id = data[k]['id'];
+ var name = (data[k]['shortname']) ?
formatScheduleShorten(data[k]['shortname'], 9) :
formatScheduleShorten(data[k]['name'], 9);
+ var type = data[k]['type'];
+ var colorCell = formatScheduleCellDateColumn(name, type);
+
+ var conflicts = new Array();
+
+ if (data[k]['conflicts'])
+ {
+ if (data[k]['conflicts'].length > 0)
+ {
+ conflicts = data[k]['conflicts'];
+ }
+ }
+ text = formatBackendScheduleDateColumn(id, name, type,
conflicts);
+ classes = colorCell + " " + type;
+ }
+ else
+ {
+ text = "free";
+ classes = "free";
+ trFunction.push(
+ {
+ event: 'click',
+ callFunction: function () {
+
schedule.newApplicationForm(col['date'], data['_from'], data['_to'])
+ }
+ }
+ )
+ }
+
+ var data_return = {
+ text: text,
+ classes: classes,
+ trAttributes: trAttributes,
+ trFunction: trFunction
+ }
+
+ return data_return;
+}
+
+function frontendScheduleDateColumn (data, col, date)
+{
+ var text = "";
+ var classes = "";
+ var trAttributes = [];
+ var trFunction = [];
+
+ var k = col.key;
+
+ if (data[k])
+ {
+ var name = (data[k]['shortname']) ?
formatScheduleShorten(data[k]['shortname'], 9) :
formatScheduleShorten(data[k]['name'], 9);
+ var type = data[k]['type'];
+ var colorCell = formatScheduleCellDateColumn(name, type);
+
+ if (data[k]['is_public'] == 0)
+ {
+ name = formatScheduleShorten('Privat arr.', 9);
+ }
+
+ text = name;
+ classes = "cellInfo " + colorCell + " " + type ;
+ trFunction.push(
+ {
+ event: 'click',
+ callFunction: function () {
+ var resource =
$(this).parent().attr('resource');
+ schedule.showInfo(data[k]['info_url'],
resource);
+ }
+ }
+ );
+ }
+ else
+ {
+ text = "free";
+ classes = "free";
+ trFunction.push(
+ {
+ event: 'click',
+ callFunction: function () {
+ var resource =
$(this).parent().attr('resource');
+
schedule.newApplicationForm(col['date'], data['_from'], data['_to'], resource);
+ }
+ }
+ );
+ }
+
+ var data_return = {
+ text: text,
+ classes: classes,
+ trAttributes: trAttributes,
+ trFunction: trFunction
+ }
+
+ return data_return;
+}
+
+function rentalSchedule (data, col, date)
+{
+ var text = "";
+ var classes = "";
+ var trAttributes = [];
+ var trFunction = [];
+
+ var k = col.key;
+
+ var needFree = true;
+ if (data[k])
+ {
+ text = data[k]['status'];
+ if (text == "Ikke ledig")
+ {
+ needFree = false;
+ }
+ }
+ else
+ {
+ text = "free";
+ classes = "free";
+ }
+
+ trAttributes.push( {attribute: 'data-id', value: data['id']} );
+ trFunction.push(
+ {
+ event: 'click',
+ callFunction: function () {
+
$(this).parent().parent().find('tr').removeClass("trselected")
+ $(this).parent().addClass("trselected");
+ $('#schedule_toolbar button').attr('disabled',
false);
+ var b_needFree = eval(needFree);
+ if (!b_needFree)
+ {
+ $('#schedule_toolbar
button.need-free').attr('disabled', true);
+ }
+ schedule.rental.data = data;
+ schedule.rental.col = col;
+ }
+ }
+ );
+
+ var data_return = {
+ text: text,
+ classes: classes,
+ trAttributes: trAttributes,
+ trFunction: trFunction
+ }
+
+ return data_return;
+}
+
+function rentalScheduleApplication (data, col, date)
+{
+ var text = "";
+ var classes = "";
+ var trAttributes = [];
+ var trFunction = [];
+
+ var validate = false;
+
+ if ( (schedule.rental.availability_from) &&
(schedule.rental.availability_to) ){
+ if (col.date >= schedule.rental.availability_from && col.date
<= schedule.rental.availability_to){
+ validate = true;
+ }
+ }
+
+ if (validate)
+ {
+ var k = col.key;
+
+ var needFree = true;
+ if (data[k])
+ {
+ text = data[k]['status'];
+ if (text == "Ikke ledig")
+ {
+ needFree = false;
+ }
+ }
+ else
+ {
+ text = "free";
+ classes = "free";
+ }
+
+ trAttributes.push( {attribute: 'data-id', value: data['id']} );
+ trFunction.push(
+ {
+ event: 'click',
+ callFunction: function () {
+
$(this).parent().parent().find('tr').removeClass("trselected")
+ $(this).parent().addClass("trselected");
+ $('#schedule_toolbar
button').attr('disabled', false);
+ var b_needFree = eval(needFree);
+ if (!b_needFree)
+ {
+ $('#schedule_toolbar
button.need-free').attr('disabled', true);
+ }
+ schedule.rental.data = data;
+ schedule.rental.col = col;
+ }
+ }
+ );
+ }
+
+ var data_return = {
+ text: text,
+ classes: classes,
+ trAttributes: trAttributes,
+ trFunction: trFunction
+ }
+
+ return data_return;
+}
+
+function rentalScheduleComposites (data, col, date)
+{
+ var text = "";
+ var classes = "";
+ var trAttributes = [];
+ var trFunction = [];
+
+ var k = col.key;
+
+ text = data[k];
+
+ trAttributes.push( {attribute: 'data-id', value: data['id']} );
+ trFunction.push(
+ {
+ event: 'click',
+ callFunction: function () {
+
$(this).parent().parent().find('tr').removeClass("trselected")
+ $(this).parent().addClass("trselected");
+ $('#composites_toolbar
button').attr('disabled', false);
+ composites.rental.data = data;
+ composites.rental.col = col;
+ }
+ }
+ );
+
+ var data_return = {
+ text: text,
+ classes: classes,
+ trAttributes: trAttributes,
+ trFunction: trFunction
+ }
+
+ return data_return;
+}
+
function restartColors()
{
colors = [
@@ -1508,6 +1955,7 @@
var color = colorMap[name];
return color;
}
+
function formatBackendScheduleDateColumn(id, name, type, conflicts)
{
var link = "";
@@ -1536,6 +1984,7 @@
}
return text;
}
+
function formatFrontendScheduleDateColumn()
{
}
@@ -1585,8 +2034,6 @@
return decodeURIComponent(string.replace(/\+/g, ' '));
}
-
-
function genericLink()
{
var data = [];
@@ -1594,6 +2041,7 @@
data['type'] = 'genericLink';
return data;
}
+
function genericLink2()
{
var data = [];
@@ -1602,7 +2050,6 @@
return data;
}
-// nl = numero links
function formatGenericLink(name, link)
{
if (!name || !link)
@@ -1614,6 +2061,7 @@
return "<a href='" + link + "'>" + name + "</a>";
}
}
+
function formatGenericLink2(name, link)
{
if (!name || !link)
@@ -1625,3 +2073,16 @@
return "<a onclick='return confirm(\"Er du sikker på at du vil
slette denne?\")' href='" + link + "'>" + name + "</a>";
}
}
+
+parseISO8601 = function (string)
+{
+ var regexp = "(([0-9]{4})(-([0-9]{1,2})(-([0-9]{1,2}))))?(
)?(([0-9]{1,2}):([0-9]{1,2}))?";
+ var d = string.match(new RegExp(regexp));
+ var year = d[2] ? (d[2] * 1) : 0;
+ date = new Date(year, (d[4] || 1) - 1, d[6] || 0);
+ if (d[9])
+ date.setHours(d[9]);
+ if (d[10])
+ date.setMinutes(d[10]);
+ return date;
+};
\ No newline at end of file
Modified: trunk/property/inc/class.menu.inc.php
===================================================================
--- trunk/property/inc/class.menu.inc.php 2016-09-28 08:47:07 UTC (rev
15747)
+++ trunk/property/inc/class.menu.inc.php 2016-09-28 10:26:36 UTC (rev
15748)
@@ -519,6 +519,11 @@
'text' => lang('Generic
import'),
'url' =>
$GLOBALS['phpgw']->link('/index.php', array('menuaction' =>
'property.uiimport.index'))
),
+ 'import_components' => array
+ (
+ 'text' => lang('import
components'),
+ 'url' =>
$GLOBALS['phpgw']->link('/index.php', array('menuaction' =>
'property.uiimport_components.index'))
+ ),
'entity' => array
(
'text' => lang('Admin entity'),
Modified: trunk/property/inc/class.uiimport.inc.php
===================================================================
--- trunk/property/inc/class.uiimport.inc.php 2016-09-28 08:47:07 UTC (rev
15747)
+++ trunk/property/inc/class.uiimport.inc.php 2016-09-28 10:26:36 UTC (rev
15748)
@@ -5,7 +5,8 @@
var $public_functions = array
(
- 'index' => true
+ 'index' => true,
+ 'components' => true
);
const DELIMITER = ";";
@@ -688,7 +689,25 @@
return false;
}
}
+
+ private function _xml2array ( $xmlObject, $out = array () )
+ {
+ foreach ( (array) $xmlObject as $index => $node )
+ {
+ $out[$index] = ( is_object($node) ||
is_array($node) ) ? $this->_xml2array ( $node ) : $node;
+ }
+
+ return $out;
+ }
+ protected function getxmldata( $path, $get_identificator = true
)
+ {
+ $xml = simplexml_load_file($path);
+ $out = $this->_xml2array($xml);
+
+ return $out;
+ }
+
protected function getcsvdata( $path, $get_identificator = true
)
{
// Open the csv file
@@ -865,4 +884,305 @@
return $file_list;
}
+
+ /**
+ * Public method.
+ *
+ * @return unknown_type
+ */
+ public function components()
+ {
+ // Set the submit button label to its initial state
+ $this->import_button_label = "Start import";
+
+ $check_method = 0;
+ $get_identificator = false;
+ /*if ($this->conv_type = phpgw::get_var('conv_type'))
+ {
+ $check_method ++;
+ $get_identificator = true;
+ }
+
+ if ($this->location_id = phpgw::get_var('location_id',
'int'))
+ {
+ $check_method ++;
+ $get_identificator = true;
+ }
+
+ if ($table = phpgw::get_var('table'))
+ {
+ $check_method ++;
+ $get_identificator = true;
+ }*/
+
+ if ($check_method > 1)
+ {
+ phpgwapi_cache::session_set('property',
'import_message', 'choose only one target!');
+ $GLOBALS['phpgw']->redirect_link('/index.php',
array('menuaction' => 'property.uiimport.components'));
+ }
+
+
+ phpgwapi_cache::session_set('property',
'import_settings', $_POST);
+
+ /*$download_template =
phpgw::get_var('download_template');
+
+ if ($download_template)
+ {
+ $this->get_template($this->location_id);
+ }*/
+
+ // If the parameter 'importsubmit' exist (submit button
in import form), set path
+ if (phpgw::get_var("importsubmit"))
+ {
+ if ($GLOBALS['phpgw']->session->is_repost() &&
!phpgw::get_var('debug', 'bool'))
+ {
+ phpgwapi_cache::session_set('property',
'import_message', 'Hmm... looks like a repost!');
+
$GLOBALS['phpgw']->redirect_link('/index.php', array('menuaction' =>
'property.uiimport.components'));
+ }
+
+
+ $start_time = time(); // Start time of import
+ $start = date("G:i:s", $start_time);
+ echo "<h3>Import started at: {$start}</h3>";
+ echo "<ul>";
+
+ /*if ($this->conv_type)
+ {
+ if (preg_match('/\.\./',
$this->conv_type))
+ {
+ throw new Exception("Not a
valid file: {$this->conv_type}");
+ }
+
+ $file = PHPGW_SERVER_ROOT .
"/property/inc/import/{$GLOBALS['phpgw_info']['user']['domain']}/{$this->conv_type}";
+
+ if (is_file($file))
+ {
+ require_once $file;
+ }
+ }
+ else
+ {
+ require_once PHPGW_SERVER_ROOT .
"/property/inc/import/import_update_generic.php";
+ }*/
+
+
+ $this->debug = phpgw::get_var('debug', 'bool');
+ //$this->import_conversion = new
import_conversion($this->location_id, $this->debug);
+
+ // Get the path for user input or use a default
path
+
+ $files = array();
+ if (isset($_FILES['file']['tmp_name']) &&
$_FILES['file']['tmp_name'])
+ {
+ $files[] = array
+ (
+ 'name' =>
$_FILES['file']['tmp_name'],
+ 'type' =>
$_FILES['file']['type']
+ );
+ }
+ else
+ {
+ $path = phpgw::get_var('path',
'string');
+ $files = $this->get_files($path);
+ }
+
+ if (!$files)
+ {
+ phpgwapi_cache::session_set('property',
'import_message', 'Ingen filer er valgt');
+
$GLOBALS['phpgw']->redirect_link('/index.php', array('menuaction' =>
'property.uiimport.components'));
+ }
+
+ $entity_categories_in_xml = array();
+ foreach ($files as $file)
+ {
+ $valid_type = true;
+ /*switch ($file['type'])
+ {
+ case
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet':
+ case
'application/vnd.oasis.opendocument.spreadsheet':
+ case 'application/vnd.ms-excel':
+ $this->csvdata =
$this->getexceldata($file['name'], $get_identificator);
+ $valid_type = true;
+ break;
+ case 'text/csv':
+ case
'text/comma-separated-values':
+ $this->csvdata =
$this->getcsvdata($file['name'], $get_identificator);
+ $valid_type = true;
+ break;
+ default:
+ throw new
Exception("Not a valid filetype: {$file['type']}");
+ }*/
+
+ $result =
$this->getxmldata($file['name'], $get_identificator);
+
+ $postnrdelkode =
$result['Prosjekter']['ProsjektNS']['Postnrplan']['PostnrdelKoder']['PostnrdelKode'];
+ $entities_name = array();
+ foreach ($postnrdelkode as $items)
+ {
+ if
($items['PostnrdelKoder']['PostnrdelKode']['Kode'])
+ {
+
$entities_name[$items['PostnrdelKoder']['PostnrdelKode']['Kode']] = array(
+ 'name'
=> $items['PostnrdelKoder']['PostnrdelKode']['Kode'].' -
'.$items['PostnrdelKoder']['PostnrdelKode']['Navn']
+ );
+ }
+ else {
+ foreach
($items['PostnrdelKoder']['PostnrdelKode'] as $item)
+ {
+
$entities_name[$item['Kode']] = array('name' => $item['Kode'].' -
'.$item['Navn']);
+ }
+ }
+ }
+
+ $posts =
$result['Prosjekter']['ProsjektNS']['Prosjektdata']['Post'];
+ foreach ($posts as $post)
+ {
+ $buildingpart =
$post['Postnrdeler']['Postnrdel'][1]['Kode'];
+
$entity_categories_in_xml[$buildingpart]['name'] =
$entities_name[$buildingpart]['name'];
+
$entity_categories_in_xml[$buildingpart]['components'][] = array(
+ array('name' =>
'benevnelse', 'value' => trim($post['Egenskaper']['Egenskap']['Verdi'])),
+ array('name' =>
'beskrivelse', 'value' => trim($post['Tekst']['Uformatert']))
+ );
+
+
//$buildingpart_in_xml[$post['Postnrdeler']['Postnrdel'][1]['Kode']] =
$post['Postnrdeler']['Postnrdel'][1]['Kode'];
+ }
+
+ //echo '<li class="info">Import:
finished step ' . print_r($buildingpart) . '</li>';
+ }
+
+ require_once PHPGW_SERVER_ROOT .
"/property/inc/import/import_update_components.php";
+
+ $import_components = new import_components();
+ $entity_categories =
$import_components->get_entity_categories();
+
+ $buildingpart_out_table = array();
+ foreach ($entity_categories_in_xml as $k => $v)
+ {
+ if (!array_key_exists((string)$k,
$entity_categories))
+ {
+ $buildingpart_parent =
substr($k, 0, strlen($k) -1);
+ $buildingpart_out_table[$k] =
array('parent' => $entity_categories[$buildingpart_parent], 'name' =>
$v['name']);
+ } else {
+
$entity_categories_in_xml[$k]['cat_id'] = $entity_categories[$k]['id'];
+
$entity_categories_in_xml[$k]['entity_id'] =
$entity_categories[$k]['entity_id'];
+ }
+ }
+
+ if (count($buildingpart_out_table))
+ {
+ $buildingpart_processed =
$import_components->add_entity_categories($buildingpart_out_table);
+
+ if
(count($buildingpart_processed['added']))
+ {
+ echo 'Entities added: <br>';
+
foreach($buildingpart_processed['added'] as $k => $v)
+ {
+
$entity_categories_in_xml[$k]['cat_id'] = $v['id'];
+
$entity_categories_in_xml[$k]['entity_id'] = $v['entity_id'];
+ echo $v['name'].'<br>';
+ }
+ }
+
+ if
(count($buildingpart_processed['not_added']))
+ {
+ echo '<br>Entities not added:
<br>';
+
foreach($buildingpart_processed['not_added'] as $k => $v)
+ {
+
unset($entity_categories_in_xml[$k]);
+ echo $v['name'].'<br>';
+ }
+ }
+ }
+
+ $components_not_added =
$import_components->add_bim_item($entity_categories_in_xml);
+ if (count($components_not_added))
+ {
+ echo '<br>Components not added: <br>';
+ foreach ($components_not_added as $k =>
$v)
+ {
+ echo $k.' => not added:
'.$v.'<br>';
+ }
+ }
+
+ //print_r($entity_categories_in_xml);
+
+ echo "</ul>";
+ $end_time = time();
+ $difference = ($end_time - $start_time) / 60;
+ $end = date("G:i:s", $end_time);
+ echo "<h3>Import ended at: {$end}. Import
lasted {$difference} minutes.";
+
+ if ($this->errors)
+ {
+ echo "<ul>";
+ foreach ($this->errors as $error)
+ {
+ echo '<li class="error">Error:
' . $error . '</li>';
+ }
+
+ echo "</ul>";
+ }
+
+ if ($this->warnings)
+ {
+ echo "<ul>";
+ foreach ($this->warnings as $warning)
+ {
+ echo '<li
class="warning">Warning: ' . $warning . '</li>';
+ }
+ echo "</ul>";
+ }
+
+ if ($this->messages)
+ {
+ echo "<ul>";
+
+ foreach ($this->messages as $message)
+ {
+ echo '<li class="info">Message:
' . $message . '</li>';
+ }
+ echo "</ul>";
+ }
+ echo '<a href="' .
$GLOBALS['phpgw']->link('/home.php') . '">Home</a>';
+ echo '</br><a href="' .
$GLOBALS['phpgw']->link('/index.php', array('menuaction' =>
'property.uiimport.components')) . '">Import</a>';
+ }
+ else
+ {
+ $import_settings =
phpgwapi_cache::session_get('property', 'import_settings');
+ $import_message =
phpgwapi_cache::session_get('property', 'import_message');
+
+ phpgwapi_cache::session_clear('property',
'import_message');
+
+
+ $home = $GLOBALS['phpgw']->link('/home.php');
+ $action = $GLOBALS['phpgw']->link('/index.php',
array('menuaction' => 'property.uiimport.components'));
+
+ //$debug_checked =
isset($import_settings['debug']) && $import_settings['debug'] ? 'checked =
"checked"' : '';
+ $html = <<<HTML
+ <h1><img
src="rental/templates/base/images/32x32/actions/document-save.png" /> Importer
( MsExcel / CSV )</h1>
+ <div id="messageHolder">{$import_message}</div>
+ <form action="{$action}" method="post"
enctype="multipart/form-data">
+ <fieldset>
+ <p>
+ <label
for="file">Choose file:</label>
+ <input type="file"
name="file" id="file" title = 'Single file'/>
+ </p>
+ <p>
+ <label for="path">Local
path:</label>
+ <input type="text"
name="path" id="path" value = '{$import_settings['path']}' title = 'Alle filer
i katalogen'/>
+ </p>
+ <p>
+ <label
for="debug">Debug:</label>
+ <input type="checkbox"
name="debug" id="debug" {$debug_checked} value ='1' />
+ </p>
+ <p>
+ <input type="submit"
name="importsubmit" value="{$this->import_button_label}" />
+ </p>
+ </fieldset>
+ </form>
+ <br><a href='$home'>Home</a>
+HTML;
+ echo $html;
+ }
+ }
+
}
\ No newline at end of file
Copied: trunk/property/inc/class.uiimport_components.inc.php (from rev 15747,
branches/dev-syncromind-2/property/inc/class.uiimport_components.inc.php)
===================================================================
--- trunk/property/inc/class.uiimport_components.inc.php
(rev 0)
+++ trunk/property/inc/class.uiimport_components.inc.php 2016-09-28
10:26:36 UTC (rev 15748)
@@ -0,0 +1,854 @@
+<?php
+ /**
+ * phpGroupWare - property: a part of a Facilities Management System.
+ *
+ * @author Sigurd Nes <address@hidden>
+ * @copyright Copyright (C) 2012 Free Software Foundation, Inc.
http://www.fsf.org/
+ * This file is part of phpGroupWare.
+ *
+ * phpGroupWare is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * phpGroupWare is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with phpGroupWare; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
02110-1301 USA
+ *
+ * @license http://www.gnu.org/licenses/gpl.html GNU General Public
License
+ * @internal Development of this application was funded by
http://www.bergen.kommune.no/
+ * @package property
+ * @subpackage logistic
+ * @version $Id: class.uigeneric_document.inc.php 14913 2016-04-11
12:27:37Z sigurdne $
+ */
+
+ phpgw::import_class('phpgwapi.uicommon_jquery');
+ phpgw::import_class('phpgwapi.jquery');
+
+ include_class('property', 'import_entity_categories', 'inc/import/');
+ include_class('property', 'import_components', 'inc/import/');
+ include_class('property', 'import_component_files', 'inc/import/');
+
+ class property_uiimport_components extends phpgwapi_uicommon_jquery
+ {
+ var $type = 'entity';
+ private $receipt = array();
+ protected $type_app = array
+ (
+ 'entity' => 'property',
+ 'catch' => 'catch'
+ );
+
+ public $public_functions = array(
+ 'query' => true,
+ 'index' => true,
+ 'get_locations_for_type' => true,
+ 'import_component_files' => true,
+ 'handle_import_files' => true,
+ 'import_components' => true,
+ 'get_attributes_from_template' => true,
+ 'download' => true
+ );
+
+ public function __construct()
+ {
+ parent::__construct();
+
+ $this->bocommon = CreateObject('property.bocommon');
+ $this->custom = CreateObject('property.custom_fields');
+ $this->bo = CreateObject('property.boadmin_entity',
true);
+ $this->acl = & $GLOBALS['phpgw']->acl;
+ $this->db = & $GLOBALS['phpgw']->db;
+ }
+
+ public function download()
+ {
+ $config = createObject('phpgwapi.config',
'component_import');
+ $values = $config->read_repository();
+ $components = $values['preview_components'];
+
+ $fields = array_keys($components[0]);
+
+ $this->bocommon->download($components, $fields,
$fields);
+ }
+
+ private function _msg_data( $receipt )
+ {
+ if (isset($receipt['error']) &&
is_array($receipt['error']))
+ {
+ foreach ($receipt['error'] as $dummy => $error)
+ {
+ $this->receipt['error'][] = $error;
+ }
+ }
+
+ if (isset($receipt['message']) &&
is_array($receipt['message']))
+ {
+ foreach ($receipt['message'] as $dummy =>
$message)
+ {
+ $this->receipt['message'][] = $message;
+ }
+ }
+
+ return $this->receipt;
+ }
+
+ private function _getexcelcolumnname( $index )
+ {
+ //Get the quotient : if the index superior to base 26
max ?
+ $quotient = $index / 26;
+ if ($quotient >= 1)
+ {
+ //If yes, get top level column + the current
column code
+ return $this->_getexcelcolumnname($quotient -
1) . chr(($index % 26) + 65);
+ }
+ else
+ {
+ //If no just return the current column code
+ return chr(65 + $index);
+ }
+ }
+
+ public function import_component_files()
+ {
+ $location_code =
phpgwapi_cache::session_get('property', 'location_code');
+ $id = phpgwapi_cache::session_get('property',
'location_item_id');
+ $attrib_name_componentID =
phpgwapi_cache::session_get('property', 'attrib_name_componentID');
+
+ if (!$attrib_name_componentID)
+ {
+ $receipt['error'][] = array('msg' =>
lang('Choose attribute name for Component ID'));
+ return $receipt;
+ }
+ if (!$location_code)
+ {
+ $receipt['error'][] = array('msg' =>
lang('Choose Location'));
+ return $receipt;
+ }
+
+ $import_component_files = new import_component_files();
+ $receipt = $import_component_files->add_files($id,
$location_code, $attrib_name_componentID);
+
+ return $receipt;
+ }
+
+ private function _getArrayItem($id, $name, $selected, $options
= array(), $no_lang = false, $attribs = '' )
+ {
+ // should be in class common.sbox
+ if ( !is_array($options) || !count($options) )
+ {
+ $options = array('no', 'yes');
+ }
+
+ $html = <<<HTML
+ <select name="$name" id="$id" $attribs>
+
+HTML;
+
+ $check = array();
+
+ if (!is_array($selected))
+ {
+ $check[$selected] = true;
+ }
+ else
+ {
+ foreach ($selected as $sel)
+ {
+ $check[$sel] = true;
+ }
+ }
+
+ foreach ( $options as $value => $option )
+ {
+ $check2 = isset( $check[$value] ) ? ' selected'
: '';
+ $option = $no_lang ? $option : lang($option);
+
+ $html .= <<<HTML
+ <option
value="{$value}"{$check2}>{$option}</option>
+
+HTML;
+ }
+ $html .= <<<HTML
+ </select>
+
+HTML;
+ return $html;
+ }
+
+ public function handle_import_files()
+ {
+ $path_upload_dir =
phpgwapi_cache::session_get('property', 'path_upload_dir');
+ if (empty($path_upload_dir))
+ {
+ return false;
+ }
+ require_once PHPGW_SERVER_ROOT .
"/property/inc/import/UploadHandler.php";
+
+ $options['upload_dir'] = $path_upload_dir;
+ $options['script_url'] =
$GLOBALS['phpgw']->link('/index.php', array('menuaction' =>
'property.uiimport_components.handle_import_files'));
+ $upload_handler = new UploadHandler($options);
+ }
+
+ private function _get_components_cached_file ()
+ {
+ $cached_file = phpgwapi_cache::session_get('property',
'components_import_file');
+
+ if ($_FILES['file']['tmp_name'])
+ {
+ if ($cached_file)
+ {
+
phpgwapi_cache::session_clear('property', 'components_import_file');
+ unlink($cached_file);
+ unset($cached_file);
+ }
+
+ $file = $_FILES['file']['tmp_name'];
+ $cached_file = "{$file}_temporary_import_file";
+
+ file_put_contents($cached_file,
file_get_contents($file));
+ phpgwapi_cache::session_set('property',
'components_import_file', $cached_file);
+ }
+
+ return $cached_file;
+ }
+
+ private function _build_sheets()
+ {
+ $cached_file = $this->_get_components_cached_file();
+ if (!$cached_file)
+ {
+ $this->receipt['error'][] = array('msg' =>
lang('Cached file not exists'));
+ return;
+ }
+
+ $objPHPExcel = PHPExcel_IOFactory::load($cached_file);
+ $AllSheets = $objPHPExcel->getSheetNames();
+
+ $sheets = array();
+ if ($AllSheets)
+ {
+ foreach ($AllSheets as $key => $sheet)
+ {
+ $sheets[] = array
+ (
+ 'id' => ($key + 1),
+ 'name' => $sheet
+ );
+ }
+ }
+
+ return $sheets;
+ }
+
+ private function _build_start_line()
+ {
+ $sheet_id = phpgwapi_cache::session_get('property',
'sheet_id');
+ $cached_file = $this->_get_components_cached_file();
+ if (!$cached_file)
+ {
+ $this->receipt['error'][] = array('msg' =>
lang('Cached file not exists'));
+ return;
+ }
+
+ $objPHPExcel = PHPExcel_IOFactory::load($cached_file);
+ $objPHPExcel->setActiveSheetIndex((int)($sheet_id - 1));
+ $highestColumm =
$objPHPExcel->getActiveSheet()->getHighestDataColumn();
+ $highestColumnIndex =
PHPExcel_Cell::columnIndexFromString($highestColumm);
+
+ $html_table = '<table class="pure-table
pure-table-bordered">';
+ $i = 0;
+ $cols = array();
+ for ($j = 0; $j < $highestColumnIndex; $j++)
+ {
+ $cols[] = $this->_getexcelcolumnname($j);
+ }
+
+ $html_table .= "<thead><tr><th align = 'center'>" .
lang('select') . "</th><th align = 'center'>" . lang('row') . "</th><th
align='center'>" . implode("</th><th align='center'>", $cols) .
'</th></tr></thead>';
+ foreach
($objPHPExcel->getActiveSheet()->getRowIterator() as $row)
+ {
+ if ($i > 20)
+ {
+ break;
+ }
+
+ $i++;
+ $row_key = $i;
+
+ $_radio = "<input type =\"radio\"
name=\"start_line\" value=\"{$row_key}\">";
+
+ $cellIterator = $row->getCellIterator();
+
$cellIterator->setIterateOnlyExistingCells(false);
+
+ $row_values = array();
+ foreach ($cellIterator as $cell)
+ {
+ if (!is_null($cell))
+ {
+ $row_values[] =
$cell->getCalculatedValue();
+ }
+ }
+ $html_table .=
"<tr><td>{$_radio}</td><td>{$row_key}</td><td>" . implode('</td><td>',
$row_values) . '</td></tr>';
+ }
+ $html_table .= '</table>';
+
+ return $html_table;
+ }
+
+ private function _build_columns()
+ {
+ $cached_file = $this->_get_components_cached_file();
+ if (!$cached_file)
+ {
+ $this->receipt['error'][] = array('msg' =>
lang('Cached file not exists'));
+ return;
+ }
+ $sheet_id = phpgwapi_cache::session_get('property',
'sheet_id');
+ $start_line = phpgwapi_cache::session_get('property',
'start_line');
+ $template_id = phpgwapi_cache::session_get('property',
'template_id');
+
+ $objPHPExcel = PHPExcel_IOFactory::load($cached_file);
+ $objPHPExcel->setActiveSheetIndex((int)($sheet_id - 1));
+ $highestColumm =
$objPHPExcel->getActiveSheet()->getHighestDataColumn();
+ $highestColumnIndex =
PHPExcel_Cell::columnIndexFromString($highestColumm);
+
+ $html_table = '<table class="pure-table
pure-table-bordered">';
+
+ $_options = array
+ (
+ '' => ' ... ',
+ 'new_column' => 'New attribute',
+ 'building_part' => '-- Building Part',
+ 'name_building_part' => '-- Name of the
Building Part',
+ 'component_id' => '-- Component ID'
+ );
+
+ $template = explode("_", $template_id);
+
+ $attributes =
$this->custom->find($this->type_app[$this->type],
".{$this->type}.{$template[0]}.{$template[1]}", 0, '', 'ASC', 'attrib_sort',
true, true);
+
+ foreach ($attributes as $attribute)
+ {
+ $_options[$attribute['name']] =
$attribute['input_text'];
+ }
+
+ $data_types = $this->bocommon->select_datatype();
+ $_options_data_type[''] = 'data type';
+ foreach($data_types as $row)
+ {
+ $_options_data_type[$row['id']] = $row['name'];
+ }
+
+ for ($j = 0; $j < $highestColumnIndex; $j++)
+ {
+ $_column = $this->_getexcelcolumnname($j);
+ $_value =
$objPHPExcel->getActiveSheet()->getCellByColumnAndRow($j,
$start_line)->getCalculatedValue();
+ //$selected = isset($columns[$_column]) &&
$columns[$_column] ? $columns[$_column] : '';
+ $selected = '';
+
+ $_listbox =
$this->_getArrayItem("column_{$_column}", "columns[{$_column}]", $selected,
$_options, true, "onchange=\"enabledAtributes('{$_column}')\" class='columns'");
+ $_listTypes =
$this->_getArrayItem("data_type_{$_column}", "data_types[{$_column}]",
$selected, $_options_data_type, true, "disabled class='data_types'");
+ $html_table .= "<tr>";
+ $html_table .= "<td>[{$_column}]
{$_value}</td>";
+ $html_table .= "<td>{$_listbox}</td>";
+ $html_table .= "<td><input type='text'
id='name_{$_column}' name='names[{$_column}]' disabled class='names'
placeholder='attribute name'></input></td>";
+ $html_table .= "<td>{$_listTypes}</td>";
+ $html_table .= "<td><input type='text'
id='precision_{$_column}' name='precision[{$_column}]' disabled
class='precision' placeholder='length'></input></td>";
+ $html_table .= "</tr>";
+ }
+
+ $html_table .= '</table>';
+
+ return $html_table;
+ }
+
+ private function _prepare_values_to_preview()
+ {
+ $columns = (array) phpgw::get_var('columns');
+ $attrib_data_types =
phpgw::get_var('attrib_data_types');
+ $attrib_names = phpgw::get_var('attrib_names');
+ $attrib_precision = phpgw::get_var('attrib_precision');
+
+ $cached_file = $this->_get_components_cached_file();
+ if (!$cached_file)
+ {
+ $this->receipt['error'][] = array('msg' =>
lang('Cached file not exists'));
+ return;
+ }
+
+ $sheet_id = phpgwapi_cache::session_get('property',
'sheet_id');
+ $start_line = phpgwapi_cache::session_get('property',
'start_line');
+ $template_id = phpgwapi_cache::session_get('property',
'template_id');
+ $attrib_name_componentID =
phpgwapi_cache::session_get('property', 'attrib_name_componentID');
+
+ $objPHPExcel = PHPExcel_IOFactory::load($cached_file);
+ $objPHPExcel->setActiveSheetIndex((int)($sheet_id - 1));
+ $rows =
$objPHPExcel->getActiveSheet()->getHighestDataRow();
+
+ $import_entity_categories = new
import_entity_categories($template_id);
+ $import_components = new import_components();
+
+ if (count($attrib_names))
+ {
+ $receipt =
$import_entity_categories->prepare_attributes_for_template($columns,
$attrib_names, $attrib_data_types, $attrib_precision);
+ $this->receipt = $this->_msg_data($receipt);
+ if ($this->receipt['error'])
+ {
+ return;
+ } else {
+ $new_attribs_for_template =
$receipt['new_attribs_for_template'];
+ }
+ }
+
+ $rows = $rows ? $rows + 1 : 0;
+
+ $building_part_out_table = array();
+ $building_part_in_table = array();
+ $import_data = array();
+
+ $list_entity_categories =
$import_entity_categories->list_entity_categories();
+
+ for ($i = $start_line; $i < $rows; $i++)
+ {
+ $_result = array();
+
+ foreach ($columns as $_row_key => $_value_key)
+ {
+ $_result[$_value_key] =
$objPHPExcel->getActiveSheet()->getCell("{$_row_key}{$i}")->getCalculatedValue();
+ }
+
+ if ((int)$_result['building_part'] ||
$_result['building_part'] === '0')
+ {
+ $cat_id = '';
+ $entity_id = '';
+
+ if
(array_key_exists((string)$_result['building_part'], $list_entity_categories))
+ {
+ if
(!empty($_result['component_id']))
+ {
+ $cat_id =
$list_entity_categories[$_result['building_part']]['id'];
+ $entity_id =
$list_entity_categories[$_result['building_part']]['entity_id'];
+
+
$building_part_in_table[$_result['building_part']] = array('entity_id' =>
$entity_id, 'cat_id' => $cat_id);
+ }
+ }
+ else {
+ if
(empty($_result['component_id']))
+ {
+
$building_part_out_table[$_result['building_part']] =
$_result['building_part'].' '.$_result['name_building_part'];
+ }
+ }
+
+ if (!empty($_result['component_id']))
+ {
+
$import_data[$_result['building_part']]['cat_id'] = $cat_id;
+
$import_data[$_result['building_part']]['entity_id'] = $entity_id;
+
+ $_result =
array($attrib_name_componentID => $_result['component_id']) + $_result;
+ $_result = array('building
part' => $_result['building_part']) + $_result;
+
+
$import_data[$_result['building_part']]['components'][] = $_result;
+ }
+ }
+ }
+
+ if (count($building_part_out_table))
+ {
+ asort($building_part_out_table);
+ $receipt =
$import_entity_categories->prepare_entity_categories($building_part_out_table);
+ $this->receipt = $this->_msg_data($receipt);
+ if ($this->receipt['error'])
+ {
+ return;
+ } else {
+ $new_entity_categories =
$receipt['new_entity_categories'];
+ }
+ }
+
+ $result = array();
+
+ if (!count($import_data))
+ {
+ $result['error'][] = array('msg' => lang('not
exist components to import'));
+ return $result;
+ }
+
+ $preview_components =
$import_components->prepare_preview_components($import_data);
+
+ $config = createObject('phpgwapi.config',
'component_import');
+
+ if (count($new_attribs_for_template))
+ {
+ $config->value('new_attribs_for_template',
serialize($new_attribs_for_template));
+ foreach($new_attribs_for_template as $attrib)
+ {
+ $values[] = $attrib['column_name'];
+ }
+ $result['new_attribs_for_template'] = $values;
+ } else {
+ $result['new_attribs_for_template'][] =
lang('Not exist attributes to insert the template');
+ }
+
+ if (count($new_entity_categories))
+ {
+ $config->value('new_entity_categories',
serialize($new_entity_categories));
+ $result['new_entity_categories'] =
array_values($new_entity_categories);
+ } else {
+ $result['new_entity_categories'][] = lang('Not
exist new entity categories');
+ }
+
+ $config->value('building_part_in_table',
serialize($building_part_in_table));
+ $config->value('preview_components',
serialize($preview_components));
+ $config->value('new_components',
serialize($import_data));
+ $config->save_repository();
+
+ return $result;
+ }
+
+ private function _save_values_import()
+ {
+ $template_id = phpgwapi_cache::session_get('property',
'template_id');
+ $attrib_name_componentID =
phpgwapi_cache::session_get('property', 'attrib_name_componentID');
+ $location_code =
phpgwapi_cache::session_get('property', 'location_code');
+
+ $import_entity_categories = new
import_entity_categories($template_id);
+ $import_components = new import_components();
+
+ $receipt =
$import_entity_categories->add_attributes_to_template();
+ $this->receipt = $this->_msg_data($receipt);
+ if ($this->receipt['error'])
+ {
+ return;
+ }
+
+ $receipt =
$import_entity_categories->add_attributes_to_categories();
+ $this->receipt = $this->_msg_data($receipt);
+ if ($this->receipt['error'])
+ {
+ return;
+ }
+
+ $config = createObject('phpgwapi.config',
'component_import');
+ $config_repository = $config->read_repository();
+ $import_data = $config_repository['new_components'];
+
+ if (!count($import_data))
+ {
+ $this->receipt['error'][] = array('msg' =>
lang("not exist components to import"));
+ return;
+ }
+
+ $building_part_processed =
$import_entity_categories->add_entity_categories();
+ if (count($building_part_processed['not_added']))
+ {
+ foreach($building_part_processed['not_added']
as $k => $v)
+ {
+ $this->receipt['message'][] =
array('msg' => lang("entity category {$v} not added"));
+ }
+ }
+
+ if (count($building_part_processed['added']))
+ {
+ foreach($building_part_processed['added'] as $k
=> $v)
+ {
+ $import_data[$k]['cat_id'] = $v['id'];
+ $import_data[$k]['entity_id'] =
$v['entity_id'];
+ }
+ $this->receipt['message'][] = array('msg' =>
lang("%1 entity category has been added",
count($building_part_processed['added'])));
+ }
+
+ $receipt =
$import_components->add_components($import_data, $location_code,
$attrib_name_componentID);
+ $this->receipt = $this->_msg_data($receipt);
+
+ return $this->receipt;
+ }
+
+ public function import_components()
+ {
+ $step = phpgw::get_var('step', 'int', 'REQUEST');
+ $save = phpgw::get_var('save', 'int', 'REQUEST');
+
+ phpgw::import_class('phpgwapi.phpexcel');
+
+ if ($step == 1)
+ {
+ $result = $this->_build_sheets();
+ }
+
+ if ($step == 2)
+ {
+ $sheet_id = phpgw::get_var('sheet_id', 'int',
'REQUEST');
+ if (!$sheet_id)
+ {
+ $this->receipt['error'][] = array('msg'
=> lang('Select Sheet'));
+ return $this->receipt;
+ }
+ phpgwapi_cache::session_set('property',
'sheet_id', $sheet_id);
+
+ $result = $this->_build_start_line();
+ }
+
+ if ($step == 3)
+ {
+ $start_line = phpgw::get_var('start_line',
'int', 'REQUEST');
+ $template_id = phpgw::get_var('template_id');
+ if (!$start_line)
+ {
+ $this->receipt['error'][] = array('msg'
=> lang('Select start line'));
+ return $this->receipt;
+ }
+ if (!$template_id)
+ {
+ $this->receipt['error'][] = array('msg'
=> lang('Select template'));
+ return $this->receipt;
+ }
+ phpgwapi_cache::session_set('property',
'start_line', $start_line);
+ phpgwapi_cache::session_set('property',
'template_id', $template_id);
+
+ $result = $this->_build_columns();
+ }
+
+ if ($step == 4)
+ {
+ $attrib_name_componentID =
phpgw::get_var('attribute_name_component_id');
+ if (!$attrib_name_componentID)
+ {
+ $this->receipt['error'][] = array('msg'
=> lang('Choose attribute name for Component ID'));
+ return $this->receipt;
+ }
+ phpgwapi_cache::session_set('property',
'attrib_name_componentID', $attrib_name_componentID);
+
+ $result = $this->_prepare_values_to_preview();
+ }
+
+ if ($step == 5 && $save)
+ {
+ $location_code =
phpgw::get_var('location_code');
+ $location_item_id =
phpgw::get_var('location_item_id');
+ if (!$location_code)
+ {
+ $this->receipt['error'][] = array('msg'
=> lang('Choose Location'));
+ return $this->receipt;
+ }
+ phpgwapi_cache::session_set('property',
'location_code', $location_code);
+ phpgwapi_cache::session_set('property',
'location_item_id', $location_item_id);
+
+ $result = $this->_save_values_import();
+ }
+
+ if ($this->receipt['error'])
+ {
+ return $this->receipt;
+ }
+
+ return $result;
+ }
+
+ /**
+ * Prepare UI
+ * @return void
+ */
+ public function index()
+ {
+ $tabs = array();
+ $tabs['locations'] = array('label' =>
lang('Locations'), 'link' => '#locations');
+ $tabs['files'] = array('label' => lang('Files'), 'link'
=> '#files', 'disable' => 0);
+ $tabs['components'] = array('label' =>
lang('Components'), 'link' => '#components', 'disable' => 1);
+ $tabs['relations'] = array('label' =>
lang('Relations'), 'link' => '#relations', 'disable' => 1);
+
+ $active_tab = 'locations';
+
+ $type_filter =
execMethod('property.soadmin_location.read', array());
+ $category_filter = $this->get_categories_for_type();
+
+ $district_filter =
$this->bocommon->select_district_list('filter');
+ array_unshift($district_filter, array('id' => '',
'name' => lang('no district')));
+
+ $part_of_town_filter = $this->get_part_of_town();
+
+ $related_def = array
+ (
+ array('key' => 'location_code', 'label' =>
lang('location'), 'sortable' => false, 'resizeable' => true),
+ array('key' => 'loc1_name', 'label' =>
lang('name'), 'sortable' => false, 'resizeable' => true)
+ );
+
+
+ $datatable_def[] = array
+ (
+ 'container' => 'datatable-container_0',
+ 'requestUrl' =>
json_encode(self::link(array('menuaction' =>
'property.uiimport_components.get_locations_for_type', 'phpgw_return_as' =>
'json'))),
+ 'ColumnDefs' => $related_def,
+ 'tabletools' => array(),
+ 'config' => array(
+ array('singleSelect' => true)
+ )
+ );
+
+ $entity_list = $this->bo->read(array('allrows' =>
true));
+ $category_list = array();
+ foreach ($entity_list as $entry)
+ {
+ $cat_list =
$this->bo->read_category(array('entity_id' => $entry['id'], 'allrows' => true));
+
+ foreach ($cat_list as $category)
+ {
+ $category_list[] = array
+ (
+ 'id' =>
"{$entry['id']}_{$category['id']}",
+ 'name' =>
"{$entry['name']}::{$category['name']}"
+ );
+ }
+ }
+
+ $form_upload_action =
$GLOBALS['phpgw']->link('/index.php', array('menuaction' =>
'property.uiimport_components.handle_import_files'));
+
+ $access_error_upload_dir = '';
+ $import_component_files = new import_component_files();
+ $receipt = $import_component_files->check_upload_dir();
+ if (($receipt['error']))
+ {
+ $access_error_upload_dir = $receipt['error'];
+ } else {
+ phpgwapi_cache::session_set('property',
'path_upload_dir', $import_component_files->get_path_upload_dir());
+ }
+
+ $data = array
+ (
+ 'datatable_def' => $datatable_def,
+ 'tabs' =>
phpgwapi_jquery::tabview_generate($tabs, $active_tab),
+
+ 'type_filter' => array('options' =>
$type_filter),
+ 'category_filter' => array('options' =>
$category_filter),
+ 'district_filter' => array('options' =>
$district_filter),
+ 'part_of_town_filter' => array('options' =>
$part_of_town_filter),
+ 'template_list' => array('options' =>
$category_list),
+ 'form_file_upload' =>
phpgwapi_jquery::form_file_upload_generate($form_upload_action),
+ 'access_error_upload_dir' =>
$access_error_upload_dir,
+ 'image_loader' =>
$GLOBALS['phpgw']->common->image('property', 'ajax-loader', '.gif', false)
+ );
+
+ self::add_javascript('property', 'portico',
'import_components.js');
+ $GLOBALS['phpgw_info']['flags']['app_header'] =
lang('property') . '::' . lang('Importer ');
+
+ self::render_template_xsl(array('import_components',
'datatable_inline'), $data);
+ }
+
+ public function get_attributes_from_template()
+ {
+ $category_template =
phpgw::get_var('category_template');
+
+ $template_info = explode('_', $category_template);
+ $template_entity_id = $template_info[0];
+ $template_cat_id = $template_info[1];
+
+ $attrib_list = $this->bo->read_attrib(array('entity_id'
=> $template_entity_id, 'cat_id' => $template_cat_id, 'allrows' => true));
+ $list = array();
+ foreach ($attrib_list as $attrib)
+ {
+ $list[] = array('id' => $attrib['column_name'],
'name' => $attrib['input_text']);
+ }
+
+ array_unshift($list, array('id' => '', 'name' =>
lang('choose attribute')));
+
+ return $list;
+ }
+
+ public function get_locations_for_type()
+ {
+ $type_id = phpgw::get_var('type_id', 'int');
+
+ if (!$type_id)
+ {
+ $type_id = 1;
+ }
+
+ $search = phpgw::get_var('search');
+ $order = phpgw::get_var('order');
+ $draw = phpgw::get_var('draw', 'int');
+ $columns = phpgw::get_var('columns');
+
+ $params = array(
+ 'start' => phpgw::get_var('start', 'int',
'REQUEST', 0),
+ 'results' => phpgw::get_var('length', 'int',
'REQUEST', 0),
+ 'query' => $search['value'],
+ 'order' =>
$columns[$order[0]['column']]['data'],
+ 'sort' => $order[0]['dir'],
+ 'cat_id' => phpgw::get_var('cat_id', 'int',
'REQUEST', 0),
+ 'type_id' => $type_id,
+ 'district_id' => phpgw::get_var('district_id',
'int', 'REQUEST', 0),
+ 'part_of_town_id' =>
phpgw::get_var('part_of_town_id', 'int', 'REQUEST', 0),
+ 'allrows' => phpgw::get_var('length', 'int') ==
-1
+ );
+
+ $solocation = CreateObject('property.solocation');
+ $locations = $solocation->read($params);
+
+ $values = array();
+ foreach($locations as $item)
+ {
+ $values[] = array(
+ 'id' => $item['id'],
+ 'location_code' =>
$item['location_code'],
+ 'loc1_name' => $item['loc1_name']
+ );
+ }
+
+ $result_data = array('results' => $values);
+
+ $result_data['total_records'] =
$solocation->total_records;
+ $result_data['draw'] = $draw;
+
+ return $this->jquery_results($result_data);
+ }
+
+ /**
+ * Fetch data from $this->bo based on parametres
+ * @return array
+ */
+ public function query()
+ {
+ return;
+ }
+
+ public function get_categories_for_type()
+ {
+ $type_id = phpgw::get_var('type_id', 'int');
+
+ if (!$type_id)
+ {
+ $type_id = 1;
+ }
+
+ $categories =
$this->bocommon->select_category_list(array
+ ('format' => 'filter',
+ 'selected' => '',
+ 'type' => 'location',
+ 'type_id' => $type_id,
+ 'order' => 'descr')
+ );
+ array_unshift($categories, array('id' => '', 'name' =>
lang('no category')));
+
+ return $categories;
+ }
+
+ public function get_data_type()
+ {
+ $values = $this->bocommon->select_datatype();
+ return $values;
+ }
+
+ public function get_part_of_town()
+ {
+ $district_id = phpgw::get_var('district_id', 'int');
+ $values =
$this->bocommon->select_part_of_town('filter', '', $district_id);
+ array_unshift($values, array('id' => '', 'name' =>
lang('no part of town')));
+
+ return $values;
+ }
+
+ }
\ No newline at end of file
Copied: trunk/property/inc/import/UploadHandler.php (from rev 15747,
branches/dev-syncromind-2/property/inc/import/UploadHandler.php)
===================================================================
--- trunk/property/inc/import/UploadHandler.php (rev 0)
+++ trunk/property/inc/import/UploadHandler.php 2016-09-28 10:26:36 UTC (rev
15748)
@@ -0,0 +1,1393 @@
+<?php
+/*
+ * jQuery File Upload Plugin PHP Class
+ * https://github.com/blueimp/jQuery-File-Upload
+ *
+ * Copyright 2010, Sebastian Tschan
+ * https://blueimp.net
+ *
+ * Licensed under the MIT license:
+ * http://www.opensource.org/licenses/MIT
+ */
+
+class UploadHandler
+{
+
+ protected $options;
+
+ // PHP File Upload error message codes:
+ // http://php.net/manual/en/features.file-upload.errors.php
+ protected $error_messages = array(
+ 1 => 'The uploaded file exceeds the upload_max_filesize directive in
php.ini',
+ 2 => 'The uploaded file exceeds the MAX_FILE_SIZE directive that was
specified in the HTML form',
+ 3 => 'The uploaded file was only partially uploaded',
+ 4 => 'No file was uploaded',
+ 6 => 'Missing a temporary folder',
+ 7 => 'Failed to write file to disk',
+ 8 => 'A PHP extension stopped the file upload',
+ 'post_max_size' => 'The uploaded file exceeds the post_max_size
directive in php.ini',
+ 'max_file_size' => 'File is too big',
+ 'min_file_size' => 'File is too small',
+ 'accept_file_types' => 'Filetype not allowed',
+ 'max_number_of_files' => 'Maximum number of files exceeded',
+ 'max_width' => 'Image exceeds maximum width',
+ 'min_width' => 'Image requires a minimum width',
+ 'max_height' => 'Image exceeds maximum height',
+ 'min_height' => 'Image requires a minimum height',
+ 'abort' => 'File upload aborted',
+ 'image_resize' => 'Failed to resize image'
+ );
+
+ protected $image_objects = array();
+
+ public function __construct($options = null, $initialize = true,
$error_messages = null) {
+ $this->response = array();
+ $this->options = array(
+ 'script_url' =>
$this->get_full_url().'/'.$this->basename($this->get_server_var('SCRIPT_NAME')),
+ 'upload_dir' =>
dirname($this->get_server_var('SCRIPT_FILENAME')).'/files/',
+ 'upload_url' => $this->get_full_url().'/files/',
+ 'input_stream' => 'php://input',
+ 'user_dirs' => false,
+ 'mkdir_mode' => 0755,
+ 'param_name' => 'files',
+ // Set the following option to 'POST', if your server does not
support
+ // DELETE requests. This is a parameter sent to the client:
+ 'delete_type' => 'POST',
+ 'access_control_allow_origin' => '*',
+ 'access_control_allow_credentials' => false,
+ 'access_control_allow_methods' => array(
+ 'OPTIONS',
+ 'HEAD',
+ 'GET',
+ 'POST',
+ 'PUT',
+ 'PATCH',
+ 'DELETE'
+ ),
+ 'access_control_allow_headers' => array(
+ 'Content-Type',
+ 'Content-Range',
+ 'Content-Disposition'
+ ),
+ // By default, allow redirects to the referer protocol+host:
+ 'redirect_allow_target' => '/^'.preg_quote(
+ parse_url($this->get_server_var('HTTP_REFERER'), PHP_URL_SCHEME)
+ .'://'
+ .parse_url($this->get_server_var('HTTP_REFERER'), PHP_URL_HOST)
+ .'/', // Trailing slash to not match subdomains by mistake
+ '/' // preg_quote delimiter param
+ ).'/',
+ // Enable to provide file downloads via GET requests to the PHP
script:
+ // 1. Set to 1 to download files via readfile method through
PHP
+ // 2. Set to 2 to send a X-Sendfile header for lighttpd/Apache
+ // 3. Set to 3 to send a X-Accel-Redirect header for nginx
+ // If set to 2 or 3, adjust the upload_url option to the base path
of
+ // the redirect parameter, e.g. '/files/'.
+ 'download_via_php' => false,
+ // Read files in chunks to avoid memory limits when
download_via_php
+ // is enabled, set to 0 to disable chunked reading of files:
+ 'readfile_chunk_size' => 10 * 1024 * 1024, // 10 MiB
+ // Defines which files can be displayed inline when downloaded:
+ 'inline_file_types' => '/\.(gif|jpe?g|png)$/i',
+ // Defines which files (based on their names) are accepted for
upload:
+ 'accept_file_types' => '/.+$/i',
+ // The php.ini settings upload_max_filesize and post_max_size
+ // take precedence over the following max_file_size setting:
+ 'max_file_size' => null,
+ 'min_file_size' => 1,
+ // The maximum number of files for the upload directory:
+ 'max_number_of_files' => null,
+ // Defines which files are handled as image files:
+ 'image_file_types' => '/\.(gif|jpe?g|png)$/i',
+ // Use exif_imagetype on all files to correct file extensions:
+ 'correct_image_extensions' => false,
+ // Image resolution restrictions:
+ 'max_width' => null,
+ 'max_height' => null,
+ 'min_width' => 1,
+ 'min_height' => 1,
+ // Set the following option to false to enable resumable uploads:
+ 'discard_aborted_uploads' => true,
+ // Set to 0 to use the GD library to scale and orient images,
+ // set to 1 to use imagick (if installed, falls back to GD),
+ // set to 2 to use the ImageMagick convert binary directly:
+ 'image_library' => 1,
+ // Uncomment the following to define an array of resource limits
+ // for imagick:
+ /*
+ 'imagick_resource_limits' => array(
+ imagick::RESOURCETYPE_MAP => 32,
+ imagick::RESOURCETYPE_MEMORY => 32
+ ),
+ */
+ // Command or path for to the ImageMagick convert binary:
+ 'convert_bin' => 'convert',
+ // Uncomment the following to add parameters in front of each
+ // ImageMagick convert call (the limit constraints seem only
+ // to have an effect if put in front):
+ /*
+ 'convert_params' => '-limit memory 32MiB -limit map 32MiB',
+ */
+ // Command or path for to the ImageMagick identify binary:
+ 'identify_bin' => 'identify',
+ 'image_versions' => array(
+ // The empty image version key defines options for the
original image:
+ '' => array(
+ // Automatically rotate images based on EXIF meta data:
+ 'auto_orient' => true
+ ),
+ // Uncomment the following to create medium sized images:
+ /*
+ 'medium' => array(
+ 'max_width' => 800,
+ 'max_height' => 600
+ ),
+ */
+ 'thumbnail' => array(
+ // Uncomment the following to use a defined directory for
the thumbnails
+ // instead of a subdirectory based on the version
identifier.
+ // Make sure that this directory doesn't allow execution
of files if you
+ // don't pose any restrictions on the type of uploaded
files, e.g. by
+ // copying the .htaccess file from the files directory for
Apache:
+ //'upload_dir' =>
dirname($this->get_server_var('SCRIPT_FILENAME')).'/thumb/',
+ //'upload_url' => $this->get_full_url().'/thumb/',
+ // Uncomment the following to force the max
+ // dimensions and e.g. create square thumbnails:
+ //'crop' => true,
+ 'max_width' => 80,
+ 'max_height' => 80
+ )
+ ),
+ 'print_response' => true
+ );
+ if ($options) {
+ $this->options = $options + $this->options;
+ }
+ if ($error_messages) {
+ $this->error_messages = $error_messages + $this->error_messages;
+ }
+ if ($initialize) {
+ $this->initialize();
+ }
+ }
+
+ protected function initialize() {
+ switch ($this->get_server_var('REQUEST_METHOD')) {
+ case 'OPTIONS':
+ case 'HEAD':
+ $this->head();
+ break;
+ case 'GET':
+ $this->get($this->options['print_response']);
+ break;
+ case 'PATCH':
+ case 'PUT':
+ case 'POST':
+ $this->post($this->options['print_response']);
+ break;
+ case 'DELETE':
+ $this->delete($this->options['print_response']);
+ break;
+ default:
+ $this->header('HTTP/1.1 405 Method Not Allowed');
+ }
+ }
+
+ protected function get_full_url() {
+ $https = !empty($_SERVER['HTTPS']) && strcasecmp($_SERVER['HTTPS'],
'on') === 0 ||
+ !empty($_SERVER['HTTP_X_FORWARDED_PROTO']) &&
+ strcasecmp($_SERVER['HTTP_X_FORWARDED_PROTO'], 'https') === 0;
+ return
+ ($https ? 'https://' : 'http://').
+ (!empty($_SERVER['REMOTE_USER']) ? $_SERVER['REMOTE_USER'].'@' :
'').
+ (isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] :
($_SERVER['SERVER_NAME'].
+ ($https && $_SERVER['SERVER_PORT'] === 443 ||
+ $_SERVER['SERVER_PORT'] === 80 ? '' :
':'.$_SERVER['SERVER_PORT']))).
+ substr($_SERVER['SCRIPT_NAME'],0, strrpos($_SERVER['SCRIPT_NAME'],
'/'));
+ }
+
+ protected function get_user_id() {
+ @session_start();
+ return session_id();
+ }
+
+ protected function get_user_path() {
+ if ($this->options['user_dirs']) {
+ return $this->get_user_id().'/';
+ }
+ return '';
+ }
+
+ protected function get_upload_path($file_name = null, $version = null) {
+ $file_name = $file_name ? $file_name : '';
+ if (empty($version)) {
+ $version_path = '';
+ } else {
+ $version_dir =
@$this->options['image_versions'][$version]['upload_dir'];
+ if ($version_dir) {
+ return $version_dir.$this->get_user_path().$file_name;
+ }
+ $version_path = $version.'/';
+ }
+ return $this->options['upload_dir'].$this->get_user_path()
+ .$version_path.$file_name;
+ }
+
+ protected function get_query_separator($url) {
+ return strpos($url, '?') === false ? '?' : '&';
+ }
+
+ protected function get_download_url($file_name, $version = null, $direct =
false) {
+ if (!$direct && $this->options['download_via_php']) {
+ $url = $this->options['script_url']
+ .$this->get_query_separator($this->options['script_url'])
+ .$this->get_singular_param_name()
+ .'='.rawurlencode($file_name);
+ if ($version) {
+ $url .= '&version='.rawurlencode($version);
+ }
+ return $url.'&download=1';
+ }
+ if (empty($version)) {
+ $version_path = '';
+ } else {
+ $version_url =
@$this->options['image_versions'][$version]['upload_url'];
+ if ($version_url) {
+ return
$version_url.$this->get_user_path().rawurlencode($file_name);
+ }
+ $version_path = rawurlencode($version).'/';
+ }
+ return $this->options['upload_url'].$this->get_user_path()
+ .$version_path.rawurlencode($file_name);
+ }
+
+ protected function set_additional_file_properties($file) {
+ $file->deleteUrl = $this->options['script_url']
+ .$this->get_query_separator($this->options['script_url'])
+ .$this->get_singular_param_name()
+ .'='.rawurlencode($file->name);
+ $file->deleteType = $this->options['delete_type'];
+ if ($file->deleteType !== 'DELETE') {
+ $file->deleteUrl .= '&_method=DELETE';
+ }
+ if ($this->options['access_control_allow_credentials']) {
+ $file->deleteWithCredentials = true;
+ }
+ }
+
+ // Fix for overflowing signed 32 bit integers,
+ // works for sizes up to 2^32-1 bytes (4 GiB - 1):
+ protected function fix_integer_overflow($size) {
+ if ($size < 0) {
+ $size += 2.0 * (PHP_INT_MAX + 1);
+ }
+ return $size;
+ }
+
+ protected function get_file_size($file_path, $clear_stat_cache = false) {
+ if ($clear_stat_cache) {
+ if (version_compare(PHP_VERSION, '5.3.0') >= 0) {
+ clearstatcache(true, $file_path);
+ } else {
+ clearstatcache();
+ }
+ }
+ return $this->fix_integer_overflow(filesize($file_path));
+ }
+
+ protected function is_valid_file_object($file_name) {
+ $file_path = $this->get_upload_path($file_name);
+ if (is_file($file_path) && $file_name[0] !== '.') {
+ return true;
+ }
+ return false;
+ }
+
+ protected function get_file_object($file_name) {
+ if ($this->is_valid_file_object($file_name)) {
+ $file = new \stdClass();
+ $file->name = $file_name;
+ $file->size = $this->get_file_size(
+ $this->get_upload_path($file_name)
+ );
+ $file->url = $this->get_download_url($file->name);
+ foreach ($this->options['image_versions'] as $version => $options)
{
+ if (!empty($version)) {
+ if (is_file($this->get_upload_path($file_name, $version)))
{
+ $file->{$version.'Url'} = $this->get_download_url(
+ $file->name,
+ $version
+ );
+ }
+ }
+ }
+ $this->set_additional_file_properties($file);
+ return $file;
+ }
+ return null;
+ }
+
+ protected function get_file_objects($iteration_method = 'get_file_object')
{
+ $upload_dir = $this->get_upload_path();
+ if (!is_dir($upload_dir)) {
+ return array();
+ }
+ return array_values(array_filter(array_map(
+ array($this, $iteration_method),
+ scandir($upload_dir)
+ )));
+ }
+
+ protected function count_file_objects() {
+ return count($this->get_file_objects('is_valid_file_object'));
+ }
+
+ protected function get_error_message($error) {
+ return isset($this->error_messages[$error]) ?
+ $this->error_messages[$error] : $error;
+ }
+
+ public function get_config_bytes($val) {
+ $val = trim($val);
+ $last = strtolower($val[strlen($val)-1]);
+ $val = (int)$val;
+ switch ($last) {
+ case 'g':
+ $val *= 1024;
+ case 'm':
+ $val *= 1024;
+ case 'k':
+ $val *= 1024;
+ }
+ return $this->fix_integer_overflow($val);
+ }
+
+ protected function validate($uploaded_file, $file, $error, $index) {
+ if ($error) {
+ $file->error = $this->get_error_message($error);
+ return false;
+ }
+ $content_length = $this->fix_integer_overflow(
+ (int)$this->get_server_var('CONTENT_LENGTH')
+ );
+ $post_max_size = $this->get_config_bytes(ini_get('post_max_size'));
+ if ($post_max_size && ($content_length > $post_max_size)) {
+ $file->error = $this->get_error_message('post_max_size');
+ return false;
+ }
+ if (!preg_match($this->options['accept_file_types'], $file->name)) {
+ $file->error = $this->get_error_message('accept_file_types');
+ return false;
+ }
+ if ($uploaded_file && is_uploaded_file($uploaded_file)) {
+ $file_size = $this->get_file_size($uploaded_file);
+ } else {
+ $file_size = $content_length;
+ }
+ if ($this->options['max_file_size'] && (
+ $file_size > $this->options['max_file_size'] ||
+ $file->size > $this->options['max_file_size'])
+ ) {
+ $file->error = $this->get_error_message('max_file_size');
+ return false;
+ }
+ if ($this->options['min_file_size'] &&
+ $file_size < $this->options['min_file_size']) {
+ $file->error = $this->get_error_message('min_file_size');
+ return false;
+ }
+ if (is_int($this->options['max_number_of_files']) &&
+ ($this->count_file_objects() >=
$this->options['max_number_of_files']) &&
+ // Ignore additional chunks of existing files:
+ !is_file($this->get_upload_path($file->name))) {
+ $file->error = $this->get_error_message('max_number_of_files');
+ return false;
+ }
+ $max_width = @$this->options['max_width'];
+ $max_height = @$this->options['max_height'];
+ $min_width = @$this->options['min_width'];
+ $min_height = @$this->options['min_height'];
+ if (($max_width || $max_height || $min_width || $min_height)
+ && preg_match($this->options['image_file_types'], $file->name)) {
+ list($img_width, $img_height) =
$this->get_image_size($uploaded_file);
+
+ // If we are auto rotating the image by default, do the checks on
+ // the correct orientation
+ if (
+ @$this->options['image_versions']['']['auto_orient'] &&
+ function_exists('exif_read_data') &&
+ ($exif = @exif_read_data($uploaded_file)) &&
+ (((int) @$exif['Orientation']) >= 5)
+ ) {
+ $tmp = $img_width;
+ $img_width = $img_height;
+ $img_height = $tmp;
+ unset($tmp);
+ }
+
+ }
+ if (!empty($img_width)) {
+ if ($max_width && $img_width > $max_width) {
+ $file->error = $this->get_error_message('max_width');
+ return false;
+ }
+ if ($max_height && $img_height > $max_height) {
+ $file->error = $this->get_error_message('max_height');
+ return false;
+ }
+ if ($min_width && $img_width < $min_width) {
+ $file->error = $this->get_error_message('min_width');
+ return false;
+ }
+ if ($min_height && $img_height < $min_height) {
+ $file->error = $this->get_error_message('min_height');
+ return false;
+ }
+ }
+ return true;
+ }
+
+ protected function upcount_name_callback($matches) {
+ $index = isset($matches[1]) ? ((int)$matches[1]) + 1 : 1;
+ $ext = isset($matches[2]) ? $matches[2] : '';
+ return ' ('.$index.')'.$ext;
+ }
+
+ protected function upcount_name($name) {
+ return preg_replace_callback(
+ '/(?:(?: \(([\d]+)\))?(\.[^.]+))?$/',
+ array($this, 'upcount_name_callback'),
+ $name,
+ 1
+ );
+ }
+
+ protected function get_unique_filename($file_path, $name, $size, $type,
$error,
+ $index, $content_range) {
+ while(is_dir($this->get_upload_path($name))) {
+ $name = $this->upcount_name($name);
+ }
+ // Keep an existing filename if this is part of a chunked upload:
+ $uploaded_bytes = $this->fix_integer_overflow((int)$content_range[1]);
+ while (is_file($this->get_upload_path($name))) {
+ if ($uploaded_bytes === $this->get_file_size(
+ $this->get_upload_path($name))) {
+ break;
+ }
+ $name = $this->upcount_name($name);
+ }
+ return $name;
+ }
+
+ protected function fix_file_extension($file_path, $name, $size, $type,
$error,
+ $index, $content_range) {
+ // Add missing file extension for known image types:
+ if (strpos($name, '.') === false &&
+ preg_match('/^image\/(gif|jpe?g|png)/', $type, $matches)) {
+ $name .= '.'.$matches[1];
+ }
+ if ($this->options['correct_image_extensions'] &&
+ function_exists('exif_imagetype')) {
+ switch (@exif_imagetype($file_path)){
+ case IMAGETYPE_JPEG:
+ $extensions = array('jpg', 'jpeg');
+ break;
+ case IMAGETYPE_PNG:
+ $extensions = array('png');
+ break;
+ case IMAGETYPE_GIF:
+ $extensions = array('gif');
+ break;
+ }
+ // Adjust incorrect image file extensions:
+ if (!empty($extensions)) {
+ $parts = explode('.', $name);
+ $extIndex = count($parts) - 1;
+ $ext = strtolower(@$parts[$extIndex]);
+ if (!in_array($ext, $extensions)) {
+ $parts[$extIndex] = $extensions[0];
+ $name = implode('.', $parts);
+ }
+ }
+ }
+ return $name;
+ }
+
+ protected function trim_file_name($file_path, $name, $size, $type, $error,
+ $index, $content_range) {
+ // Remove path information and dots around the filename, to prevent
uploading
+ // into different directories or replacing hidden system files.
+ // Also remove control characters and spaces (\x00..\x20) around the
filename:
+ $name = trim($this->basename(stripslashes($name)), ".\x00..\x20");
+ // Use a timestamp for empty filenames:
+ if (!$name) {
+ $name = str_replace('.', '-', microtime(true));
+ }
+ return $name;
+ }
+
+ protected function get_file_name($file_path, $name, $size, $type, $error,
+ $index, $content_range) {
+ $name = $this->trim_file_name($file_path, $name, $size, $type, $error,
+ $index, $content_range);
+ return $this->get_unique_filename(
+ $file_path,
+ $this->fix_file_extension($file_path, $name, $size, $type, $error,
+ $index, $content_range),
+ $size,
+ $type,
+ $error,
+ $index,
+ $content_range
+ );
+ }
+
+ protected function get_scaled_image_file_paths($file_name, $version) {
+ $file_path = $this->get_upload_path($file_name);
+ if (!empty($version)) {
+ $version_dir = $this->get_upload_path(null, $version);
+ if (!is_dir($version_dir)) {
+ mkdir($version_dir, $this->options['mkdir_mode'], true);
+ }
+ $new_file_path = $version_dir.'/'.$file_name;
+ } else {
+ $new_file_path = $file_path;
+ }
+ return array($file_path, $new_file_path);
+ }
+
+ protected function gd_get_image_object($file_path, $func, $no_cache =
false) {
+ if (empty($this->image_objects[$file_path]) || $no_cache) {
+ $this->gd_destroy_image_object($file_path);
+ $this->image_objects[$file_path] = $func($file_path);
+ }
+ return $this->image_objects[$file_path];
+ }
+
+ protected function gd_set_image_object($file_path, $image) {
+ $this->gd_destroy_image_object($file_path);
+ $this->image_objects[$file_path] = $image;
+ }
+
+ protected function gd_destroy_image_object($file_path) {
+ $image = (isset($this->image_objects[$file_path])) ?
$this->image_objects[$file_path] : null ;
+ return $image && imagedestroy($image);
+ }
+
+ protected function gd_imageflip($image, $mode) {
+ if (function_exists('imageflip')) {
+ return imageflip($image, $mode);
+ }
+ $new_width = $src_width = imagesx($image);
+ $new_height = $src_height = imagesy($image);
+ $new_img = imagecreatetruecolor($new_width, $new_height);
+ $src_x = 0;
+ $src_y = 0;
+ switch ($mode) {
+ case '1': // flip on the horizontal axis
+ $src_y = $new_height - 1;
+ $src_height = -$new_height;
+ break;
+ case '2': // flip on the vertical axis
+ $src_x = $new_width - 1;
+ $src_width = -$new_width;
+ break;
+ case '3': // flip on both axes
+ $src_y = $new_height - 1;
+ $src_height = -$new_height;
+ $src_x = $new_width - 1;
+ $src_width = -$new_width;
+ break;
+ default:
+ return $image;
+ }
+ imagecopyresampled(
+ $new_img,
+ $image,
+ 0,
+ 0,
+ $src_x,
+ $src_y,
+ $new_width,
+ $new_height,
+ $src_width,
+ $src_height
+ );
+ return $new_img;
+ }
+
+ protected function gd_orient_image($file_path, $src_img) {
+ if (!function_exists('exif_read_data')) {
+ return false;
+ }
+ $exif = @exif_read_data($file_path);
+ if ($exif === false) {
+ return false;
+ }
+ $orientation = (int)@$exif['Orientation'];
+ if ($orientation < 2 || $orientation > 8) {
+ return false;
+ }
+ switch ($orientation) {
+ case 2:
+ $new_img = $this->gd_imageflip(
+ $src_img,
+ defined('IMG_FLIP_VERTICAL') ? IMG_FLIP_VERTICAL : 2
+ );
+ break;
+ case 3:
+ $new_img = imagerotate($src_img, 180, 0);
+ break;
+ case 4:
+ $new_img = $this->gd_imageflip(
+ $src_img,
+ defined('IMG_FLIP_HORIZONTAL') ? IMG_FLIP_HORIZONTAL : 1
+ );
+ break;
+ case 5:
+ $tmp_img = $this->gd_imageflip(
+ $src_img,
+ defined('IMG_FLIP_HORIZONTAL') ? IMG_FLIP_HORIZONTAL : 1
+ );
+ $new_img = imagerotate($tmp_img, 270, 0);
+ imagedestroy($tmp_img);
+ break;
+ case 6:
+ $new_img = imagerotate($src_img, 270, 0);
+ break;
+ case 7:
+ $tmp_img = $this->gd_imageflip(
+ $src_img,
+ defined('IMG_FLIP_VERTICAL') ? IMG_FLIP_VERTICAL : 2
+ );
+ $new_img = imagerotate($tmp_img, 270, 0);
+ imagedestroy($tmp_img);
+ break;
+ case 8:
+ $new_img = imagerotate($src_img, 90, 0);
+ break;
+ default:
+ return false;
+ }
+ $this->gd_set_image_object($file_path, $new_img);
+ return true;
+ }
+
+ protected function gd_create_scaled_image($file_name, $version, $options) {
+ if (!function_exists('imagecreatetruecolor')) {
+ error_log('Function not found: imagecreatetruecolor');
+ return false;
+ }
+ list($file_path, $new_file_path) =
+ $this->get_scaled_image_file_paths($file_name, $version);
+ $type = strtolower(substr(strrchr($file_name, '.'), 1));
+ switch ($type) {
+ case 'jpg':
+ case 'jpeg':
+ $src_func = 'imagecreatefromjpeg';
+ $write_func = 'imagejpeg';
+ $image_quality = isset($options['jpeg_quality']) ?
+ $options['jpeg_quality'] : 75;
+ break;
+ case 'gif':
+ $src_func = 'imagecreatefromgif';
+ $write_func = 'imagegif';
+ $image_quality = null;
+ break;
+ case 'png':
+ $src_func = 'imagecreatefrompng';
+ $write_func = 'imagepng';
+ $image_quality = isset($options['png_quality']) ?
+ $options['png_quality'] : 9;
+ break;
+ default:
+ return false;
+ }
+ $src_img = $this->gd_get_image_object(
+ $file_path,
+ $src_func,
+ !empty($options['no_cache'])
+ );
+ $image_oriented = false;
+ if (!empty($options['auto_orient']) && $this->gd_orient_image(
+ $file_path,
+ $src_img
+ )) {
+ $image_oriented = true;
+ $src_img = $this->gd_get_image_object(
+ $file_path,
+ $src_func
+ );
+ }
+ $max_width = $img_width = imagesx($src_img);
+ $max_height = $img_height = imagesy($src_img);
+ if (!empty($options['max_width'])) {
+ $max_width = $options['max_width'];
+ }
+ if (!empty($options['max_height'])) {
+ $max_height = $options['max_height'];
+ }
+ $scale = min(
+ $max_width / $img_width,
+ $max_height / $img_height
+ );
+ if ($scale >= 1) {
+ if ($image_oriented) {
+ return $write_func($src_img, $new_file_path, $image_quality);
+ }
+ if ($file_path !== $new_file_path) {
+ return copy($file_path, $new_file_path);
+ }
+ return true;
+ }
+ if (empty($options['crop'])) {
+ $new_width = $img_width * $scale;
+ $new_height = $img_height * $scale;
+ $dst_x = 0;
+ $dst_y = 0;
+ $new_img = imagecreatetruecolor($new_width, $new_height);
+ } else {
+ if (($img_width / $img_height) >= ($max_width / $max_height)) {
+ $new_width = $img_width / ($img_height / $max_height);
+ $new_height = $max_height;
+ } else {
+ $new_width = $max_width;
+ $new_height = $img_height / ($img_width / $max_width);
+ }
+ $dst_x = 0 - ($new_width - $max_width) / 2;
+ $dst_y = 0 - ($new_height - $max_height) / 2;
+ $new_img = imagecreatetruecolor($max_width, $max_height);
+ }
+ // Handle transparency in GIF and PNG images:
+ switch ($type) {
+ case 'gif':
+ case 'png':
+ imagecolortransparent($new_img, imagecolorallocate($new_img,
0, 0, 0));
+ case 'png':
+ imagealphablending($new_img, false);
+ imagesavealpha($new_img, true);
+ break;
+ }
+ $success = imagecopyresampled(
+ $new_img,
+ $src_img,
+ $dst_x,
+ $dst_y,
+ 0,
+ 0,
+ $new_width,
+ $new_height,
+ $img_width,
+ $img_height
+ ) && $write_func($new_img, $new_file_path, $image_quality);
+ $this->gd_set_image_object($file_path, $new_img);
+ return $success;
+ }
+
+ protected function imagick_get_image_object($file_path, $no_cache = false)
{
+ if (empty($this->image_objects[$file_path]) || $no_cache) {
+ $this->imagick_destroy_image_object($file_path);
+ $image = new \Imagick();
+ if (!empty($this->options['imagick_resource_limits'])) {
+ foreach ($this->options['imagick_resource_limits'] as $type =>
$limit) {
+ $image->setResourceLimit($type, $limit);
+ }
+ }
+ $image->readImage($file_path);
+ $this->image_objects[$file_path] = $image;
+ }
+ return $this->image_objects[$file_path];
+ }
+
+ protected function imagick_set_image_object($file_path, $image) {
+ $this->imagick_destroy_image_object($file_path);
+ $this->image_objects[$file_path] = $image;
+ }
+
+ protected function imagick_destroy_image_object($file_path) {
+ $image = (isset($this->image_objects[$file_path])) ?
$this->image_objects[$file_path] : null ;
+ return $image && $image->destroy();
+ }
+
+ protected function imagick_orient_image($image) {
+ $orientation = $image->getImageOrientation();
+ $background = new \ImagickPixel('none');
+ switch ($orientation) {
+ case \imagick::ORIENTATION_TOPRIGHT: // 2
+ $image->flopImage(); // horizontal flop around y-axis
+ break;
+ case \imagick::ORIENTATION_BOTTOMRIGHT: // 3
+ $image->rotateImage($background, 180);
+ break;
+ case \imagick::ORIENTATION_BOTTOMLEFT: // 4
+ $image->flipImage(); // vertical flip around x-axis
+ break;
+ case \imagick::ORIENTATION_LEFTTOP: // 5
+ $image->flopImage(); // horizontal flop around y-axis
+ $image->rotateImage($background, 270);
+ break;
+ case \imagick::ORIENTATION_RIGHTTOP: // 6
+ $image->rotateImage($background, 90);
+ break;
+ case \imagick::ORIENTATION_RIGHTBOTTOM: // 7
+ $image->flipImage(); // vertical flip around x-axis
+ $image->rotateImage($background, 270);
+ break;
+ case \imagick::ORIENTATION_LEFTBOTTOM: // 8
+ $image->rotateImage($background, 270);
+ break;
+ default:
+ return false;
+ }
+ $image->setImageOrientation(\imagick::ORIENTATION_TOPLEFT); // 1
+ return true;
+ }
+
+ protected function imagick_create_scaled_image($file_name, $version,
$options) {
+ list($file_path, $new_file_path) =
+ $this->get_scaled_image_file_paths($file_name, $version);
+ $image = $this->imagick_get_image_object(
+ $file_path,
+ !empty($options['crop']) || !empty($options['no_cache'])
+ );
+ if ($image->getImageFormat() === 'GIF') {
+ // Handle animated GIFs:
+ $images = $image->coalesceImages();
+ foreach ($images as $frame) {
+ $image = $frame;
+ $this->imagick_set_image_object($file_name, $image);
+ break;
+ }
+ }
+ $image_oriented = false;
+ if (!empty($options['auto_orient'])) {
+ $image_oriented = $this->imagick_orient_image($image);
+ }
+ $new_width = $max_width = $img_width = $image->getImageWidth();
+ $new_height = $max_height = $img_height = $image->getImageHeight();
+ if (!empty($options['max_width'])) {
+ $new_width = $max_width = $options['max_width'];
+ }
+ if (!empty($options['max_height'])) {
+ $new_height = $max_height = $options['max_height'];
+ }
+ if (!($image_oriented || $max_width < $img_width || $max_height <
$img_height)) {
+ if ($file_path !== $new_file_path) {
+ return copy($file_path, $new_file_path);
+ }
+ return true;
+ }
+ $crop = !empty($options['crop']);
+ if ($crop) {
+ $x = 0;
+ $y = 0;
+ if (($img_width / $img_height) >= ($max_width / $max_height)) {
+ $new_width = 0; // Enables proportional scaling based on
max_height
+ $x = ($img_width / ($img_height / $max_height) - $max_width) /
2;
+ } else {
+ $new_height = 0; // Enables proportional scaling based on
max_width
+ $y = ($img_height / ($img_width / $max_width) - $max_height) /
2;
+ }
+ }
+ $success = $image->resizeImage(
+ $new_width,
+ $new_height,
+ isset($options['filter']) ? $options['filter'] :
\imagick::FILTER_LANCZOS,
+ isset($options['blur']) ? $options['blur'] : 1,
+ $new_width && $new_height // fit image into constraints if not to
be cropped
+ );
+ if ($success && $crop) {
+ $success = $image->cropImage(
+ $max_width,
+ $max_height,
+ $x,
+ $y
+ );
+ if ($success) {
+ $success = $image->setImagePage($max_width, $max_height, 0, 0);
+ }
+ }
+ $type = strtolower(substr(strrchr($file_name, '.'), 1));
+ switch ($type) {
+ case 'jpg':
+ case 'jpeg':
+ if (!empty($options['jpeg_quality'])) {
+ $image->setImageCompression(\imagick::COMPRESSION_JPEG);
+
$image->setImageCompressionQuality($options['jpeg_quality']);
+ }
+ break;
+ }
+ if (!empty($options['strip'])) {
+ $image->stripImage();
+ }
+ return $success && $image->writeImage($new_file_path);
+ }
+
+ protected function imagemagick_create_scaled_image($file_name, $version,
$options) {
+ list($file_path, $new_file_path) =
+ $this->get_scaled_image_file_paths($file_name, $version);
+ $resize = @$options['max_width']
+ .(empty($options['max_height']) ? '' : 'X'.$options['max_height']);
+ if (!$resize && empty($options['auto_orient'])) {
+ if ($file_path !== $new_file_path) {
+ return copy($file_path, $new_file_path);
+ }
+ return true;
+ }
+ $cmd = $this->options['convert_bin'];
+ if (!empty($this->options['convert_params'])) {
+ $cmd .= ' '.$this->options['convert_params'];
+ }
+ $cmd .= ' '.escapeshellarg($file_path);
+ if (!empty($options['auto_orient'])) {
+ $cmd .= ' -auto-orient';
+ }
+ if ($resize) {
+ // Handle animated GIFs:
+ $cmd .= ' -coalesce';
+ if (empty($options['crop'])) {
+ $cmd .= ' -resize '.escapeshellarg($resize.'>');
+ } else {
+ $cmd .= ' -resize '.escapeshellarg($resize.'^');
+ $cmd .= ' -gravity center';
+ $cmd .= ' -crop '.escapeshellarg($resize.'+0+0');
+ }
+ // Make sure the page dimensions are correct (fixes offsets of
animated GIFs):
+ $cmd .= ' +repage';
+ }
+ if (!empty($options['convert_params'])) {
+ $cmd .= ' '.$options['convert_params'];
+ }
+ $cmd .= ' '.escapeshellarg($new_file_path);
+ exec($cmd, $output, $error);
+ if ($error) {
+ error_log(implode('\n', $output));
+ return false;
+ }
+ return true;
+ }
+
+ protected function get_image_size($file_path) {
+ if ($this->options['image_library']) {
+ if (extension_loaded('imagick')) {
+ $image = new \Imagick();
+ try {
+ if (@$image->pingImage($file_path)) {
+ $dimensions = array($image->getImageWidth(),
$image->getImageHeight());
+ $image->destroy();
+ return $dimensions;
+ }
+ return false;
+ } catch (\Exception $e) {
+ error_log($e->getMessage());
+ }
+ }
+ if ($this->options['image_library'] === 2) {
+ $cmd = $this->options['identify_bin'];
+ $cmd .= ' -ping '.escapeshellarg($file_path);
+ exec($cmd, $output, $error);
+ if (!$error && !empty($output)) {
+ // image.jpg JPEG 1920x1080 1920x1080+0+0 8-bit sRGB 465KB
0.000u 0:00.000
+ $infos = preg_split('/\s+/', substr($output[0],
strlen($file_path)));
+ $dimensions = preg_split('/x/', $infos[2]);
+ return $dimensions;
+ }
+ return false;
+ }
+ }
+ if (!function_exists('getimagesize')) {
+ error_log('Function not found: getimagesize');
+ return false;
+ }
+ return @getimagesize($file_path);
+ }
+
+ protected function create_scaled_image($file_name, $version, $options) {
+ if ($this->options['image_library'] === 2) {
+ return $this->imagemagick_create_scaled_image($file_name,
$version, $options);
+ }
+ if ($this->options['image_library'] && extension_loaded('imagick')) {
+ return $this->imagick_create_scaled_image($file_name, $version,
$options);
+ }
+ return $this->gd_create_scaled_image($file_name, $version, $options);
+ }
+
+ protected function destroy_image_object($file_path) {
+ if ($this->options['image_library'] && extension_loaded('imagick')) {
+ return $this->imagick_destroy_image_object($file_path);
+ }
+ }
+
+ protected function is_valid_image_file($file_path) {
+ if (!preg_match($this->options['image_file_types'], $file_path)) {
+ return false;
+ }
+ if (function_exists('exif_imagetype')) {
+ return @exif_imagetype($file_path);
+ }
+ $image_info = $this->get_image_size($file_path);
+ return $image_info && $image_info[0] && $image_info[1];
+ }
+
+ protected function handle_image_file($file_path, $file) {
+ $failed_versions = array();
+ foreach ($this->options['image_versions'] as $version => $options) {
+ if ($this->create_scaled_image($file->name, $version, $options)) {
+ if (!empty($version)) {
+ $file->{$version.'Url'} = $this->get_download_url(
+ $file->name,
+ $version
+ );
+ } else {
+ $file->size = $this->get_file_size($file_path, true);
+ }
+ } else {
+ $failed_versions[] = $version ? $version : 'original';
+ }
+ }
+ if (count($failed_versions)) {
+ $file->error = $this->get_error_message('image_resize')
+ .' ('.implode($failed_versions, ', ').')';
+ }
+ // Free memory:
+ $this->destroy_image_object($file_path);
+ }
+
+ protected function handle_file_upload($uploaded_file, $name, $size, $type,
$error,
+ $index = null, $content_range = null) {
+ $file = new \stdClass();
+ $file->name = $this->get_file_name($uploaded_file, $name, $size,
$type, $error,
+ $index, $content_range);
+ $file->size = $this->fix_integer_overflow((int)$size);
+ $file->type = $type;
+ if ($this->validate($uploaded_file, $file, $error, $index)) {
+ $this->handle_form_data($file, $index);
+ $upload_dir = $this->get_upload_path();
+ if (!is_dir($upload_dir)) {
+ mkdir($upload_dir, $this->options['mkdir_mode'], true);
+ }
+ $file_path = $this->get_upload_path($file->name);
+ $append_file = $content_range && is_file($file_path) &&
+ $file->size > $this->get_file_size($file_path);
+ if ($uploaded_file && is_uploaded_file($uploaded_file)) {
+ // multipart/formdata uploads (POST method uploads)
+ if ($append_file) {
+ file_put_contents(
+ $file_path,
+ fopen($uploaded_file, 'r'),
+ FILE_APPEND
+ );
+ } else {
+ move_uploaded_file($uploaded_file, $file_path);
+ }
+ } else {
+ // Non-multipart uploads (PUT method support)
+ file_put_contents(
+ $file_path,
+ fopen($this->options['input_stream'], 'r'),
+ $append_file ? FILE_APPEND : 0
+ );
+ }
+ $file_size = $this->get_file_size($file_path, $append_file);
+ if ($file_size === $file->size) {
+ $file->url = $this->get_download_url($file->name);
+ if ($this->is_valid_image_file($file_path)) {
+ $this->handle_image_file($file_path, $file);
+ }
+ } else {
+ $file->size = $file_size;
+ if (!$content_range &&
$this->options['discard_aborted_uploads']) {
+ unlink($file_path);
+ $file->error = $this->get_error_message('abort');
+ }
+ }
+ $this->set_additional_file_properties($file);
+ }
+ return $file;
+ }
+
+ protected function readfile($file_path) {
+ $file_size = $this->get_file_size($file_path);
+ $chunk_size = $this->options['readfile_chunk_size'];
+ if ($chunk_size && $file_size > $chunk_size) {
+ $handle = fopen($file_path, 'rb');
+ while (!feof($handle)) {
+ echo fread($handle, $chunk_size);
+ @ob_flush();
+ @flush();
+ }
+ fclose($handle);
+ return $file_size;
+ }
+ return readfile($file_path);
+ }
+
+ protected function body($str) {
+ echo $str;
+ }
+
+ protected function header($str) {
+ header($str);
+ }
+
+ protected function get_upload_data($id) {
+ return @$_FILES[$id];
+ }
+
+ protected function get_post_param($id) {
+ return @$_POST[$id];
+ }
+
+ protected function get_query_param($id) {
+ return @$_GET[$id];
+ }
+
+ protected function get_server_var($id) {
+ return @$_SERVER[$id];
+ }
+
+ protected function handle_form_data($file, $index) {
+ // Handle form data, e.g. $_POST['description'][$index]
+ }
+
+ protected function get_version_param() {
+ return
$this->basename(stripslashes($this->get_query_param('version')));
+ }
+
+ protected function get_singular_param_name() {
+ return substr($this->options['param_name'], 0, -1);
+ }
+
+ protected function get_file_name_param() {
+ $name = $this->get_singular_param_name();
+ return $this->basename(stripslashes($this->get_query_param($name)));
+ }
+
+ protected function get_file_names_params() {
+ $params = $this->get_query_param($this->options['param_name']);
+ if (!$params) {
+ return null;
+ }
+ foreach ($params as $key => $value) {
+ $params[$key] = $this->basename(stripslashes($value));
+ }
+ return $params;
+ }
+
+ protected function get_file_type($file_path) {
+ switch (strtolower(pathinfo($file_path, PATHINFO_EXTENSION))) {
+ case 'jpeg':
+ case 'jpg':
+ return 'image/jpeg';
+ case 'png':
+ return 'image/png';
+ case 'gif':
+ return 'image/gif';
+ default:
+ return '';
+ }
+ }
+
+ protected function download() {
+ switch ($this->options['download_via_php']) {
+ case 1:
+ $redirect_header = null;
+ break;
+ case 2:
+ $redirect_header = 'X-Sendfile';
+ break;
+ case 3:
+ $redirect_header = 'X-Accel-Redirect';
+ break;
+ default:
+ return $this->header('HTTP/1.1 403 Forbidden');
+ }
+ $file_name = $this->get_file_name_param();
+ if (!$this->is_valid_file_object($file_name)) {
+ return $this->header('HTTP/1.1 404 Not Found');
+ }
+ if ($redirect_header) {
+ return $this->header(
+ $redirect_header.': '.$this->get_download_url(
+ $file_name,
+ $this->get_version_param(),
+ true
+ )
+ );
+ }
+ $file_path = $this->get_upload_path($file_name,
$this->get_version_param());
+ // Prevent browsers from MIME-sniffing the content-type:
+ $this->header('X-Content-Type-Options: nosniff');
+ if (!preg_match($this->options['inline_file_types'], $file_name)) {
+ $this->header('Content-Type: application/octet-stream');
+ $this->header('Content-Disposition: attachment;
filename="'.$file_name.'"');
+ } else {
+ $this->header('Content-Type: '.$this->get_file_type($file_path));
+ $this->header('Content-Disposition: inline;
filename="'.$file_name.'"');
+ }
+ $this->header('Content-Length: '.$this->get_file_size($file_path));
+ $this->header('Last-Modified: '.gmdate('D, d M Y H:i:s T',
filemtime($file_path)));
+ $this->readfile($file_path);
+ }
+
+ protected function send_content_type_header() {
+ $this->header('Vary: Accept');
+ if (strpos($this->get_server_var('HTTP_ACCEPT'), 'application/json')
!== false) {
+ $this->header('Content-type: application/json');
+ } else {
+ $this->header('Content-type: text/plain');
+ }
+ }
+
+ protected function send_access_control_headers() {
+ $this->header('Access-Control-Allow-Origin:
'.$this->options['access_control_allow_origin']);
+ $this->header('Access-Control-Allow-Credentials: '
+ .($this->options['access_control_allow_credentials'] ? 'true' :
'false'));
+ $this->header('Access-Control-Allow-Methods: '
+ .implode(', ', $this->options['access_control_allow_methods']));
+ $this->header('Access-Control-Allow-Headers: '
+ .implode(', ', $this->options['access_control_allow_headers']));
+ }
+
+ public function generate_response($content, $print_response = true) {
+ $this->response = $content;
+ if ($print_response) {
+ $json = json_encode($content);
+ $redirect = stripslashes($this->get_post_param('redirect'));
+ if ($redirect &&
preg_match($this->options['redirect_allow_target'], $redirect)) {
+ $this->header('Location: '.sprintf($redirect,
rawurlencode($json)));
+ return;
+ }
+ $this->head();
+ if ($this->get_server_var('HTTP_CONTENT_RANGE')) {
+ $files = isset($content[$this->options['param_name']]) ?
+ $content[$this->options['param_name']] : null;
+ if ($files && is_array($files) && is_object($files[0]) &&
$files[0]->size) {
+ $this->header('Range: 0-'.(
+ $this->fix_integer_overflow((int)$files[0]->size) - 1
+ ));
+ }
+ }
+ $this->body($json);
+ }
+ return $content;
+ }
+
+ public function get_response () {
+ return $this->response;
+ }
+
+ public function head() {
+ $this->header('Pragma: no-cache');
+ $this->header('Cache-Control: no-store, no-cache, must-revalidate');
+ $this->header('Content-Disposition: inline; filename="files.json"');
+ // Prevent Internet Explorer from MIME-sniffing the content-type:
+ $this->header('X-Content-Type-Options: nosniff');
+ if ($this->options['access_control_allow_origin']) {
+ $this->send_access_control_headers();
+ }
+ $this->send_content_type_header();
+ }
+
+ public function get($print_response = true) {
+ if ($print_response && $this->get_query_param('download')) {
+ return $this->download();
+ }
+ $file_name = $this->get_file_name_param();
+ if ($file_name) {
+ $response = array(
+ $this->get_singular_param_name() =>
$this->get_file_object($file_name)
+ );
+ } else {
+ $response = array(
+ $this->options['param_name'] => $this->get_file_objects()
+ );
+ }
+ return $this->generate_response($response, $print_response);
+ }
+
+ public function post($print_response = true) {
+ if ($this->get_query_param('_method') === 'DELETE') {
+ return $this->delete($print_response);
+ }
+ $upload = $this->get_upload_data($this->options['param_name']);
+ // Parse the Content-Disposition header, if available:
+ $content_disposition_header =
$this->get_server_var('HTTP_CONTENT_DISPOSITION');
+ $file_name = $content_disposition_header ?
+ rawurldecode(preg_replace(
+ '/(^[^"]+")|("$)/',
+ '',
+ $content_disposition_header
+ )) : null;
+ // Parse the Content-Range header, which has the following form:
+ // Content-Range: bytes 0-524287/2000000
+ $content_range_header = $this->get_server_var('HTTP_CONTENT_RANGE');
+ $content_range = $content_range_header ?
+ preg_split('/[^0-9]+/', $content_range_header) : null;
+ $size = $content_range ? $content_range[3] : null;
+ $files = array();
+ if ($upload) {
+ if (is_array($upload['tmp_name'])) {
+ // param_name is an array identifier like "files[]",
+ // $upload is a multi-dimensional array:
+ foreach ($upload['tmp_name'] as $index => $value) {
+ $files[] = $this->handle_file_upload(
+ $upload['tmp_name'][$index],
+ $file_name ? $file_name : $upload['name'][$index],
+ $size ? $size : $upload['size'][$index],
+ $upload['type'][$index],
+ $upload['error'][$index],
+ $index,
+ $content_range
+ );
+ }
+ } else {
+ // param_name is a single object identifier like "file",
+ // $upload is a one-dimensional array:
+ $files[] = $this->handle_file_upload(
+ isset($upload['tmp_name']) ? $upload['tmp_name'] : null,
+ $file_name ? $file_name : (isset($upload['name']) ?
+ $upload['name'] : null),
+ $size ? $size : (isset($upload['size']) ?
+ $upload['size'] :
$this->get_server_var('CONTENT_LENGTH')),
+ isset($upload['type']) ?
+ $upload['type'] :
$this->get_server_var('CONTENT_TYPE'),
+ isset($upload['error']) ? $upload['error'] : null,
+ null,
+ $content_range
+ );
+ }
+ }
+ $response = array($this->options['param_name'] => $files);
+ return $this->generate_response($response, $print_response);
+ }
+
+ public function delete($print_response = true) {
+ $file_names = $this->get_file_names_params();
+ if (empty($file_names)) {
+ $file_names = array($this->get_file_name_param());
+ }
+ $response = array();
+ foreach ($file_names as $file_name) {
+ $file_path = $this->get_upload_path($file_name);
+ $success = is_file($file_path) && $file_name[0] !== '.' &&
unlink($file_path);
+ if ($success) {
+ foreach ($this->options['image_versions'] as $version =>
$options) {
+ if (!empty($version)) {
+ $file = $this->get_upload_path($file_name, $version);
+ if (is_file($file)) {
+ unlink($file);
+ }
+ }
+ }
+ }
+ $response[$file_name] = $success;
+ }
+ return $this->generate_response($response, $print_response);
+ }
+
+ protected function basename($filepath, $suffix = null) {
+ $splited = preg_split('/\//', rtrim ($filepath, '/ '));
+ return substr(basename('X'.$splited[count($splited)-1], $suffix), 1);
+ }
+}
Copied: trunk/property/inc/import/class.import_component_files.inc.php (from
rev 15747,
branches/dev-syncromind-2/property/inc/import/class.import_component_files.inc.php)
===================================================================
--- trunk/property/inc/import/class.import_component_files.inc.php
(rev 0)
+++ trunk/property/inc/import/class.import_component_files.inc.php
2016-09-28 10:26:36 UTC (rev 15748)
@@ -0,0 +1,286 @@
+<?php
+
+ class import_component_files
+ {
+ public function __construct()
+ {
+ $this->acl = & $GLOBALS['phpgw']->acl;
+ $this->db = & $GLOBALS['phpgw']->db;
+
+ $this->fakebase = '/temp_files_components';
+ $this->path_upload_dir =
$GLOBALS['phpgw_info']['server']['files_dir'].$this->fakebase.'/';
+ }
+
+ public function get_path_upload_dir()
+ {
+ return $this->path_upload_dir;
+ }
+
+ public function check_upload_dir()
+ {
+ $rs = $this->create_document_dir();
+ if (!$rs)
+ {
+ $receipt['error'] = lang('failed to create
directory') . ': ' . $this->fakebase;
+ }
+
+ if (!is_writable($this->path_upload_dir))
+ {
+ $receipt['error'] = lang('Not have permission
to access the directory') . ': ' . $this->fakebase;
+ }
+
+ return $receipt;
+ }
+
+ private function create_document_dir()
+ {
+ if (is_dir($this->path_upload_dir))
+ {
+ return true;
+ }
+
+ $old = umask(0);
+ $rs = mkdir($this->path_upload_dir, 0755);
+ umask($old);
+
+ return $rs;
+ }
+
+ private function _valid_row($row)
+ {
+ if (empty($row[0]) && empty($row[(count($row)-1)]))
+ {
+ return false;
+ }
+
+ if ($row[0] == 'Nummer3' && $row[(count($row)-1)] ==
'Filsti')
+ {
+ return false;
+ }
+
+ return true;
+ }
+
+ public function add_files($id, $location_code,
$attrib_name_componentID)
+ {
+ $exceldata =
$this->_getexceldata($_FILES['file']['tmp_name'], true);
+ $component_files = array();
+ $message = array();
+
+ foreach ($exceldata as $row)
+ {
+ if (!$this->_valid_row($row))
+ {
+ continue;
+ }
+
+ $array_path = explode("\\",
$row[(count($row)-1)]);
+
+ $component_files[$row[0]][] = array(
+ 'name' => $row[1],
+ 'desription' => $row[2],
+ 'file' =>
$array_path[count($array_path)-1]
+ );
+ }
+
+ $this->db->transaction_begin();
+
+ try
+ {
+ $this->db->Exception_On_Error = true;
+
+ $count = 0;
+ foreach ($component_files as $k => $files)
+ {
+ if (empty($k))
+ {
+ $component = array('id' => $id,
'location_id' => $GLOBALS['phpgw']->locations->get_id('property',
'.location.'.count(explode('-', $location_code))));
+ }
+ else {
+ $component =
$this->_get_component($k, $attrib_name_componentID);
+ if( empty($component['id']) ||
empty($component['location_id']))
+ {
+ throw new
Exception("component {$k} does not exist");
+ }
+ }
+
+ foreach($files as $file_data)
+ {
+ $file = $file_data['file'];
+
+ if
(!is_file($this->path_upload_dir.$file))
+ {
+ throw new
Exception("the file {$file} does not exist, component: {$k}");
+ }
+
+ $file_id =
$this->_save_file($file_data);
+ if (!$file_id)
+ {
+ throw new
Exception("failed to save file {$file}, component: {$k}");
+ }
+
+ $result =
$this->_save_file_relation($component['id'], $component['location_id'],
$file_id);
+ if (!$result)
+ {
+ throw new
Exception("failed to save relation, file: {$file}, component: {$k}");
+ }
+ $count++;
+ }
+ }
+ $this->db->Exception_On_Error = false;
+ }
+ catch (Exception $e)
+ {
+ if ($e)
+ {
+ $this->db->transaction_abort();
+ $message['error'][] = array('msg' =>
$e->getMessage());
+ return $message;
+ }
+ }
+
+ $this->db->transaction_commit();
+ $message['message'][] = array('msg' => lang('%1 files
saved successfully', $count));
+
+ return $message;
+ }
+
+
+ private function _get_component( $query,
$attrib_name_componentID)
+ {
+ if ($query)
+ {
+ $query = $this->db->db_addslashes($query);
+ }
+
+ $sql = "SELECT * FROM fm_bim_item WHERE
json_representation->>'{$attrib_name_componentID}' = '{$query}'";
+
+ $this->db->query($sql, __LINE__, __FILE__);
+
+ $values = array();
+
+ if ($this->db->next_record())
+ {
+ $values['id'] = $this->db->f('id');
+ $values['location_id'] =
$this->db->f('location_id');
+ }
+
+ return $values;
+ }
+
+
+ private function _save_file( $file_data )
+ {
+ $metadata = array();
+
+ $tmp_file = $file_data['file'];
+
+ $bofiles = CreateObject('property.bofiles');
+
+ $file_name = str_replace(' ', '_', $tmp_file);
+
+ $to_file = $bofiles->fakebase . '/generic_document/'
.$file_name;
+
+ $receipt =
$bofiles->create_document_dir("generic_document");
+ if (count($receipt['error']))
+ {
+ throw new Exception('failed to create
directory');
+ }
+ $bofiles->vfs->override_acl = 1;
+
+ $file_id = $bofiles->vfs->cp3(array(
+ 'from' =>
$this->path_upload_dir.$tmp_file,
+ 'to' => $to_file,
+ 'id' => '',
+ 'relatives' => array(RELATIVE_NONE |
VFS_REAL, RELATIVE_ALL)));
+ $bofiles->vfs->override_acl = 0;
+
+ if ($file_id)
+ {
+ $metadata['report_date'] =
phpgwapi_datetime::date_to_timestamp(date('Y-m-d'));
+ $metadata['title'] = $file_data['name'];
+ $metadata['descr'] = $file_data['desription'];
+
+ $values_insert = array
+ (
+ 'file_id' => $file_id,
+ 'metadata' => json_encode($metadata)
+ );
+
+ $this->db->query("INSERT INTO
phpgw_vfs_filedata (" . implode(',', array_keys($values_insert)) . ') VALUES ('
+ .
$this->db->validate_insert(array_values($values_insert)) . ')', __LINE__,
__FILE__);
+ }
+
+ return $file_id;
+ }
+
+
+ private function _save_file_relation( $id, $location_id,
$file_id )
+ {
+ $date =
phpgwapi_datetime::date_to_timestamp(date('Y-m-d'));
+
+ $values_insert = array
+ (
+ 'file_id' => (int)$file_id,
+ 'location_id' => (int)$location_id,
+ 'location_item_id' => (int)$id,
+ 'is_private' => 0,
+ 'account_id' =>
$GLOBALS['phpgw_info']['user']['account_id'],
+ 'entry_date' => $date,
+ 'start_date' => $date,
+ 'end_date' => $date
+ );
+
+ return $this->db->query("INSERT INTO
phpgw_vfs_file_relation (" . implode(',', array_keys($values_insert)) . ')
VALUES ('
+ .
$this->db->validate_insert(array_values($values_insert)) . ')', __LINE__,
__FILE__);
+ }
+
+ protected function _getexceldata( $path, $get_identificator =
false )
+ {
+ phpgw::import_class('phpgwapi.phpexcel');
+
+ $objPHPExcel = PHPExcel_IOFactory::load($path);
+ $objPHPExcel->setActiveSheetIndex(0);
+
+ $result = array();
+
+ $highestColumm =
$objPHPExcel->getActiveSheet()->getHighestDataColumn();
+
+ $highestColumnIndex =
PHPExcel_Cell::columnIndexFromString($highestColumm);
+
+ $rows =
$objPHPExcel->getActiveSheet()->getHighestDataRow();
+
+ $start = $get_identificator ? 3 : 1; // Read the first
line to get the headers out of the way
+
+ if ($get_identificator)
+ {
+ $this->identificator =
$objPHPExcel->getActiveSheet()->getCellByColumnAndRow(0,
1)->getCalculatedValue();
+ for ($j = 0; $j < $highestColumnIndex; $j++)
+ {
+ $this->fields[] =
$objPHPExcel->getActiveSheet()->getCellByColumnAndRow($j,
2)->getCalculatedValue();
+ }
+ }
+ else
+ {
+ for ($j = 0; $j < $highestColumnIndex; $j++)
+ {
+ $this->fields[] =
$objPHPExcel->getActiveSheet()->getCellByColumnAndRow($j,
1)->getCalculatedValue();
+ }
+ }
+
+ $rows = $rows ? $rows + 1 : 0;
+ for ($row = $start; $row < $rows; $row++)
+ {
+ $_result = array();
+
+ for ($j = 0; $j < $highestColumnIndex; $j++)
+ {
+ $_result[] =
$objPHPExcel->getActiveSheet()->getCellByColumnAndRow($j,
$row)->getCalculatedValue();
+ }
+
+ $result[] = $_result;
+ }
+
+ return $result;
+ }
+ }
\ No newline at end of file
Copied: trunk/property/inc/import/class.import_components.inc.php (from rev
15747,
branches/dev-syncromind-2/property/inc/import/class.import_components.inc.php)
===================================================================
--- trunk/property/inc/import/class.import_components.inc.php
(rev 0)
+++ trunk/property/inc/import/class.import_components.inc.php 2016-09-28
10:26:36 UTC (rev 15748)
@@ -0,0 +1,337 @@
+<?php
+
+ class import_components
+ {
+
+ protected $db;
+ var $type = 'entity';
+ protected $sql;
+ protected $type_app = array
+ (
+ 'entity' => 'property',
+ 'catch' => 'catch'
+ );
+
+ public function __construct()
+ {
+ $this->account =
(int)$GLOBALS['phpgw_info']['user']['account_id'];
+ $this->db = & $GLOBALS['phpgw']->db;
+ $this->join = $this->db->join;
+ $this->bo = CreateObject('property.boadmin_entity',
true);
+ //$this->bo_entity = CreateObject('property.boentity',
true);
+ $this->custom = CreateObject('property.custom_fields');
+ $this->bocommon = CreateObject('property.bocommon');
+ }
+
+ private function _get_attributes($entity_id, $cat_id)
+ {
+ $attributes =
$this->custom->find($this->type_app[$this->type],
".{$this->type}.{$entity_id}.{$cat_id}", 0, '', 'ASC', 'attrib_sort', true,
true);
+
+ $values = array();
+ foreach($attributes as $attribute)
+ {
+ $values[] = array(
+ 'name' =>
$attribute['name'],
+ 'datatype' =>
$attribute['datatype'],
+ 'precision' =>
$attribute['precision'],
+ 'history' =>
$attribute['history'],
+ 'attrib_id' =>
$attribute['attrib_id'],
+ 'nullable' =>
$attribute['nullable'],
+ 'input_text' =>
$attribute['input_text'],
+ 'disabled' =>
$attribute['disabled'],
+ 'value' =>
$attribute['value']
+ );
+ }
+
+ return $values;
+ }
+
+ private function _set_attributes_values($values, $attributes)
+ {
+ foreach($attributes as &$attribute)
+ {
+ $attribute['value'] =
$values[$attribute['name']];
+ }
+
+ return $attributes;
+ }
+
+ public function prepare_preview_components($import_data)
+ {
+ $components = array();
+
+ foreach ($import_data as $entity)
+ {
+ foreach ($entity['components'] as $values)
+ {
+ unset($values['component_id']);
+ unset($values['building_part']);
+ unset($values['name_building_part']);
+ $components[] = $values;
+ }
+ }
+
+ return $components;
+ }
+
+ private function _get_component( $query,
$attrib_name_componentID)
+ {
+ if ($query)
+ {
+ $query = $this->db->db_addslashes($query);
+ }
+
+ $sql = "SELECT * FROM fm_bim_item WHERE
json_representation->>'{$attrib_name_componentID}' = '{$query}'";
+
+ $this->db->query($sql, __LINE__, __FILE__);
+
+ $values = array();
+
+ if ($this->db->next_record())
+ {
+ $values['id'] = $this->db->f('id');
+ $values['location_id'] =
$this->db->f('location_id');
+ }
+
+ return $values;
+ }
+
+ public function add_components($import_data, $location_code,
$attrib_name_componentID)
+ {
+ $message = array();
+
+ $location_code_values = explode('-', $location_code);
+ $i = 0;
+ $location = array();
+ foreach ($location_code_values as $loc)
+ {
+ $i++;
+ $location['loc'.$i] = $loc;
+ }
+
+ $this->db->transaction_begin();
+
+ try
+ {
+ $this->db->Exception_On_Error = true;
+ $count_added = 0;
+ $count_updated = 0;
+ foreach ($import_data as $entity)
+ {
+ $attributes =
$this->_get_attributes($entity['entity_id'], $entity['cat_id']);
+
+ foreach ($entity['components'] as
$values)
+ {
+ $attributes_values =
$this->_set_attributes_values($values, $attributes);
+ $values_insert =
$this->_populate(array('location_code'=>$location_code, 'location'=>$location),
$attributes_values);
+
+ $component =
$this->_get_component($values_insert[$attrib_name_componentID],
$attrib_name_componentID);
+ if ($component['id'])
+ {
+ $receipt =
$this->_edit_eav($values_insert, $entity['entity_id'], $entity['cat_id'],
$component['id']);
+ $action = 'updated';
+ $count_updated++;
+ } else {
+ $receipt =
$this->_save_eav($values_insert, $entity['entity_id'], $entity['cat_id']);
+ $action = 'added';
+ $count_added++;
+ }
+
+ if (!$receipt)
+ {
+ throw new
Exception("component {$values_insert[$attrib_name_componentID]} not {$action}");
+ }
+ }
+ }
+ $this->db->Exception_On_Error = false;
+ }
+ catch (Exception $e)
+ {
+ if ($e)
+ {
+ $this->db->transaction_abort();
+ $message['error'][] = array('msg' =>
$e->getMessage());
+ return $message;
+ }
+ }
+
+ $this->db->transaction_commit();
+
+ if ($count_added)
+ {
+ $message['message'][] = array('msg' => lang('%1
components added successfully', $count_added));
+ }
+ if ($count_updated)
+ {
+ $message['message'][] = array('msg' => lang('%1
components updated successfully', $count_updated));
+ }
+
+ return $message;
+ }
+
+ private function _save_eav( $data, $entity_id, $cat_id )
+ {
+ $location_id = (int)
$GLOBALS['phpgw']->locations->get_id($this->type_app[$this->type],
".{$this->type}.{$entity_id}.{$cat_id}");
+
+ $this->db->query("SELECT id as type FROM fm_bim_type
WHERE location_id = {$location_id}", __LINE__, __FILE__);
+ $this->db->next_record();
+ $type = $this->db->f('type');
+ $id = $this->db->next_id('fm_bim_item', array('type' =>
$type));
+
+ if (function_exists('com_create_guid') === true)
+ {
+ $guid = trim(com_create_guid(), '{}');
+ }
+ else
+ {
+ $guid =
sprintf('%04X%04X-%04X-%04X-%04X-%04X%04X%04X', mt_rand(0, 65535), mt_rand(0,
65535), mt_rand(0, 65535), mt_rand(16384, 20479), mt_rand(32768, 49151),
mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(0, 65535));
+ }
+
+ $values_insert = array
+ (
+ 'id' => $id,
+ 'location_id' => $location_id,
+ 'type' => $type,
+ 'guid' => $guid,
+ 'json_representation' => json_encode($data),
+ 'model' => 0,
+ 'p_location_id' =>
isset($data['p_location_id']) && $data['p_location_id'] ?
$data['p_location_id'] : '',
+ 'p_id' => isset($data['p_id']) && $data['p_id']
? $data['p_id'] : '',
+ 'location_code' => $data['location_code'],
+ 'loc1' => $data['loc1'],
+ 'address' => $data['address'],
+ 'entry_date' => time(),
+ 'user_id' => $this->account
+ );
+
+ $result = $this->db->query("INSERT INTO fm_bim_item ("
. implode(',', array_keys($values_insert)) . ') VALUES ('
+ .
$this->db->validate_insert(array_values($values_insert)) . ')', __LINE__,
__FILE__);
+
+ return $result;
+ }
+
+ protected function _edit_eav( $data, $entity_id, $cat_id, $id )
+ {
+ $location_id = (int)
$GLOBALS['phpgw']->locations->get_id($this->type_app[$this->type],
".{$this->type}.{$entity_id}.{$cat_id}");
+ $id = (int)$id;
+
+ $this->db->query("SELECT id as type FROM fm_bim_type
WHERE location_id = {$location_id}", __LINE__, __FILE__);
+ $this->db->next_record();
+ $type = (int)$this->db->f('type');
+
+ $location_name = str_replace('.', '_', $location_name);
+
+ $value_set = array
+ (
+ 'json_representation' => json_encode($data),
+ 'p_location_id' =>
isset($data['p_location_id']) && $data['p_location_id'] ?
$data['p_location_id'] : '',
+ 'p_id' => isset($data['p_id']) && $data['p_id']
? $data['p_id'] : '',
+ 'location_code' => $data['location_code'],
+ 'loc1' => $data['loc1'],
+ 'address' => $data['address'],
+ 'org_unit_id' => $data['org_unit_id'],
+ 'entity_group_id' => $data['entity_group_id'],
+ 'modified_by' => $this->account,
+ 'modified_on' => time()
+ );
+
+ $value_set = $this->db->validate_update($value_set);
+ return $this->db->query("UPDATE fm_bim_item SET
$value_set WHERE id = $id AND type = {$type}", __LINE__, __FILE__);
+ }
+
+ private function _populate( $values, $values_attribute )
+ {
+
+ if (is_array($values_attribute))
+ {
+ $values_attribute =
$this->custom->convert_attribute_save($values_attribute);
+ }
+
+ $values_insert = array();
+
+ if (isset($values['street_name']) &&
$values['street_name'])
+ {
+ $address[] = $values['street_name'];
+ $address[] = $values['street_number'];
+ $address = $this->db->db_addslashes(implode("
", $address));
+ }
+
+ if (!isset($address) || !$address)
+ {
+ $address = isset($values['location_name']) ?
$this->db->db_addslashes($values['location_name']) : '';
+ }
+
+ if (isset($address) && $address)
+ {
+ $values_insert['address'] = $address;
+ }
+
+ if (isset($values['location_code']) &&
$values['location_code'])
+ {
+ $values_insert['location_code'] =
$values['location_code'];
+ }
+
+ if (isset($values['location']) &&
is_array($values['location']))
+ {
+ foreach ($values['location'] as $input_name =>
$value)
+ {
+ if (isset($value) && $value)
+ {
+ $values_insert[$input_name] =
$value;
+ }
+ }
+ }
+
+ if (isset($values['extra']) &&
is_array($values['extra']))
+ {
+ foreach ($values['extra'] as $input_name =>
$value)
+ {
+ if (isset($value) && $value)
+ {
+ $values_insert[$input_name] =
$value;
+ }
+ }
+ }
+
+ if (isset($values_attribute) &&
is_array($values_attribute))
+ {
+ foreach ($values_attribute as $entry)
+ {
+ if ($entry['value'])
+ {
+ if ($entry['datatype'] == 'C'
|| $entry['datatype'] == 'T' || $entry['datatype'] == 'V' || $entry['datatype']
== 'link')
+ {
+ $entry['value'] =
$this->db->db_addslashes($entry['value']);
+ }
+ $values_insert[$entry['name']]
= $entry['value'];
+
+ if ($entry['history'] == 1)
+ {
+
$history_set[$entry['attrib_id']] = array
+ (
+ 'value' =>
$entry['value'],
+ 'date' =>
$this->bocommon->date_to_timestamp($entry['date'])
+ );
+ }
+ }
+ }
+ }
+
+ if (isset($values_insert['p_num']) &&
$values_insert['p_num'])
+ {
+ // $p_category =
$admin_entity->read_single_category($values_insert['p_entity_id'],
$values_insert['p_cat_id']);
+ // $p_id = (int)
ltrim($values_insert['p_num'], $p_category['prefix']);
+ $p_id = $values_insert['p_num'];
+ $p_location_id =
$GLOBALS['phpgw']->locations->get_id($this->type_app[$this->type],
".{$this->type}.{$values_insert['p_entity_id']}.{$values_insert['p_cat_id']}");
+ }
+
+ if (isset($values_insert['p_num']) &&
$values_insert['p_num'])
+ {
+ $values_insert['p_id'] = $p_id;
+ $values_insert['p_location_id'] =
$p_location_id;
+ }
+
+ return $values_insert;
+ }
+
+ }
\ No newline at end of file
Copied: trunk/property/inc/import/class.import_entity_categories.inc.php (from
rev 15747,
branches/dev-syncromind-2/property/inc/import/class.import_entity_categories.inc.php)
===================================================================
--- trunk/property/inc/import/class.import_entity_categories.inc.php
(rev 0)
+++ trunk/property/inc/import/class.import_entity_categories.inc.php
2016-09-28 10:26:36 UTC (rev 15748)
@@ -0,0 +1,504 @@
+<?php
+
+ class import_entity_categories
+ {
+
+ protected $db;
+ var $type = 'entity';
+ var $array_entity_categories = array();
+ protected $sql;
+ protected $type_app = array
+ (
+ 'entity' => 'property',
+ 'catch' => 'catch'
+ );
+ protected $entity_id_from_template = null;
+ protected $cat_id_from_template = array();
+
+ protected $array_cat_id = array();
+ protected $template_id = null;
+
+ public function __construct($template_id)
+ {
+ $this->db = & $GLOBALS['phpgw']->db;
+ $this->join = $this->db->join;
+ $this->bo = CreateObject('property.boadmin_entity',
true);
+ $this->custom = CreateObject('property.custom_fields');
+ $this->config = createObject('phpgwapi.config',
'component_import');
+ $this->config_repository =
$this->config->read_repository();
+
+ $this->array_entity_categories = array(
+ '0' => array('name' => '0 Generelt'),
+ '01' => array('name' => '01 Informasjon og
hjelp'),
+ '02' => array('name' => '02 Krav til
dokumentasjon'),
+
+ '1' => array('name' => '1 Brannsikring'),
+ '11' => array('name' => '11 Branntekniske
krav'),
+ '12' => array('name' => '12
Tegninger(.pdf)/o-planer'),
+ '13' => array('name' => '13 Brannteknisk
dokumentasjon')
+ );
+
+ if ($template_id)
+ {
+ $this->template_id = $template_id;
+ $template = explode("_", $template_id);
+
+ $this->entity_id_from_template = $template[0];
+ $this->cat_id_from_template = $template[1];
+
+ $this->array_cat_id[1] = '309';
+ $this->array_cat_id[2] = '310';
+ $this->array_cat_id[3] = $template[1];
+ $this->array_cat_id[4] = $template[1];
+ }
+ }
+
+ private function _get_cat_id_by_building_part($building_part)
+ {
+ return $this->array_cat_id[strlen($building_part)];
+ }
+
+ private function _search_parent_category(&$new_categories,
$list_entity_categories, $building_part)
+ {
+ $receipt = array();
+
+ for($x = 1; $x <= (strlen($building_part)-1); $x++)
+ {
+ $parents[] = substr($building_part, 0, $x);
+ }
+
+ foreach($parents as $item)
+ {
+ if (array_key_exists($item, $new_categories))
+ {
+ continue;
+ }
+
+ if (array_key_exists($item,
$list_entity_categories))
+ {
+ continue;
+ }
+
+ $category =
$this->array_entity_categories[$item];
+ if (empty($category['name']))
+ {
+ $receipt['error'][] = array('msg' =>
lang('Building Part '.$item.' not define'));
+ break;
+ }
+
+ $new_categories[$item] = $category['name'];
+ }
+
+ return $receipt;
+ }
+
+ public function
prepare_entity_categories($building_part_out_table)
+ {
+ $new_categories = array();
+ $receipt = array();
+
+ $list_entity_categories =
$this->list_entity_categories();
+
+ foreach ($building_part_out_table as $building_part =>
$name)
+ {
+ if (strlen($building_part) > 1)
+ {
+ $receipt =
$this->_search_parent_category($new_categories, $list_entity_categories,
$building_part);
+ if ($receipt['error'])
+ {
+ break;
+ }
+ }
+
+ $new_categories[$building_part] = $name;
+ }
+
+ if ($receipt['error'])
+ {
+ return $receipt;
+ }
+
+ $receipt['new_entity_categories'] = $new_categories;
+
+ return $receipt;
+ }
+
+
+ public function add_entity_categories ()
+ {
+ $receipt = array();
+
+ $new_categories =
$this->config_repository['new_entity_categories'];
+ if (!count($new_categories))
+ {
+ $receipt['message'][] = array('msg' =>
lang('Not exist new categories to insert'));
+ return $receipt;
+ }
+
+ $categories = array();
+ $parent_id = NULL;
+
+ foreach ($new_categories as $building_part => $name)
+ {
+ if (strlen($building_part) == 1)
+ {
+ $parent_id = NULL;
+ }
+ else
+ {
+ $building_part_parent =
substr($building_part, 0, (strlen($building_part)-1));
+ $values =
$this->list_entity_categories(array('building_part' => $building_part_parent));
+ $parent_id =
$values[$building_part_parent]['id'];
+ if (!$parent_id)
+ {
+
$categories['not_added'][$building_part] = array('name' => $name);
+ break;
+ }
+ }
+
+ $category_id = $this->_save_category($name,
$parent_id, $building_part);
+
+ if ($category_id)
+ {
+ $categories['added'][$building_part] =
array('id' => $category_id, 'entity_id' => $this->entity_id_from_template,
'name' => $name);
+ }
+ else {
+
$categories['not_added'][$building_part] = array('name' => $name);
+ }
+ }
+
+ return $categories;
+ }
+
+ private function _save_category ($name, $parent_id,
$building_part)
+ {
+ $cat_id =
$this->_get_cat_id_by_building_part($building_part);
+ $entity_id = $this->entity_id_from_template;
+ $values = array();
+
+ $attrib_list = $this->bo->read_attrib(array('entity_id'
=> $entity_id, 'cat_id' => $cat_id, 'allrows' => true));
+ foreach ($attrib_list as $attrib)
+ {
+ $values['template_attrib'][] = $attrib['id'];
+ }
+ $values['category_template'] = $entity_id.'_'.$cat_id;
+ $values['parent_id'] = $parent_id;
+ $values['name'] = $name;
+ $values['descr'] = $name;
+ $values['entity_id'] = $entity_id;
+ $values['fileupload'] = 1;
+ $values['loc_link'] = 1;
+ $values['is_eav'] = 1;
+
+ $receipt = $this->bo->save_category($values);
+
+ return $receipt['id'];
+ }
+
+ public function list_entity_categories ($data = array())
+ {
+ $querymethod = '';
+ if ($data['parent_id'])
+ {
+ $querymethod .= " AND parent_id =
".$data['parent_id'];
+ }
+ if ($data['building_part'])
+ {
+ $querymethod .= " AND name LIKE
'".$data['building_part']." %'";
+ }
+
+ $sql = "SELECT * FROM fm_entity_category WHERE
entity_id = {$this->entity_id_from_template} {$querymethod}";
+ $this->db->query($sql, __LINE__, __FILE__);
+
+ while ($this->db->next_record())
+ {
+ $building_part = explode(' ',
trim($this->db->f('name')))[0];
+
+ $values[$building_part] = array
+ (
+ 'id' => $this->db->f('id'),
+ 'name' => $this->db->f('name'),
+ 'building_part' => $building_part,
+ 'location_id' =>
$this->db->f('location_id'),
+ 'parent_id' =>
$this->db->f('parent_id'),
+ 'entity_id' => $this->db->f('entity_id')
+ );
+ }
+
+ return $values;
+ }
+
+
+ public function add_attributes_to_categories ()
+ {
+ $receipt = array();
+
+ $building_part_in_table =
$this->config_repository['building_part_in_table'];
+ if (!count($building_part_in_table))
+ {
+ $receipt['message'][] = array('msg' =>
lang('Not exist new categories to insert'));
+ return $receipt;
+ }
+
+ $count = 0;
+ foreach ($building_part_in_table as $k => $v)
+ {
+ $values2 = array
+ (
+ 'entity_id' => $v['entity_id'],
+ 'cat_id' => $v['cat_id'],
+ 'category_template' =>
$this->template_id,
+ 'selected' => ''
+ );
+
+ $result = $this->_add_attrib_from_template(
$values2 );
+ if (empty($result))
+ {
+ continue;
+ }
+
+ if ($result['error'])
+ {
+ foreach ($result['error'] as $error)
+ {
+ $receipt['error'][] =
array('msg' => $error['msg'].'. Building Part: '. $k);
+ }
+ } else {
+ $count++;
+ }
+ }
+
+ if ($count)
+ {
+ $receipt['message'][] = array('msg' =>
lang('attributes has been added to %1 entity categories', $count));
+ }
+
+ return $receipt;
+ }
+
+ private function _add_attrib_from_template( $values )
+ {
+ $receipt = array();
+
+ $template_info = explode('_',
$values['category_template']);
+ $template_entity_id = $template_info[0];
+ $template_cat_id = $template_info[1];
+
+ $attrib_group_list =
$this->bo->read_attrib_group(array('entity_id' => $template_entity_id,
+ 'cat_id' => $template_cat_id, 'allrows' =>
true));
+
+ foreach ($attrib_group_list as $attrib_group)
+ {
+ $group = array
+ (
+ 'appname' =>
$this->type_app[$this->type],
+ 'location' =>
".{$this->type}.{$values['entity_id']}.{$values['cat_id']}",
+ 'group_name' => $attrib_group['name'],
+ 'descr' => $attrib_group['descr'],
+ 'remark' => $attrib_group['remark']
+ );
+ $this->custom->add_group($group);
+ }
+
+ $attrib_list = $this->bo->read_attrib(array('entity_id'
=> $values['entity_id'], 'cat_id' => $values['cat_id'], 'allrows' => true));
+ $column_names = array();
+ foreach ($attrib_list as $attrib)
+ {
+ $column_names[] = $attrib['column_name'];
+ }
+
+ $attrib_list_template =
$this->bo->read_attrib(array('entity_id' => $template_entity_id, 'cat_id' =>
$template_cat_id, 'allrows' => true));
+ $template_attribs = array();
+ foreach ($attrib_list_template as $attrib)
+ {
+ if(!in_array($attrib['column_name'],
$column_names, true))
+ {
+ $template_attribs[] =
$this->bo->read_single_attrib($template_entity_id, $template_cat_id,
$attrib['id']);
+ }
+ }
+
+ if (!count($template_attribs))
+ {
+ return array();
+ }
+
+ foreach ($template_attribs as $attrib)
+ {
+ $attrib['appname'] =
$this->type_app[$this->type];
+ $attrib['location'] =
".{$this->type}.{$values['entity_id']}.{$values['cat_id']}";
+
+ $choices = array();
+ if (isset($attrib['choice']) &&
$attrib['choice'])
+ {
+ $choices = $attrib['choice'];
+ unset($attrib['choice']);
+ }
+
+ $id = $this->custom->add($attrib);
+ if ($choices)
+ {
+ foreach ($choices as $choice)
+ {
+ $attrib['new_choice'] =
$choice['value'];
+ $attrib['id'] = $id;
@@ Diff output truncated at 153600 characters. @@
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Fmsystem-commits] [15748] Backport 15258:15747 from Syncromind,
sigurdne <=