Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
MaarchCourrier
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Redmine
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Harbor Registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Maarch
MaarchCourrier
Commits
13c26a89
Commit
13c26a89
authored
13 years ago
by
Giovannoni Laurent
Browse files
Options
Downloads
Patches
Plain Diff
fix: export proble
parent
0b6d5ada
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
core/trunk/core/class/ExportControler.php
+152
-152
152 additions, 152 deletions
core/trunk/core/class/ExportControler.php
core/trunk/core/class/class_request.php
+5
-1
5 additions, 1 deletion
core/trunk/core/class/class_request.php
with
157 additions
and
153 deletions
core/trunk/core/class/ExportControler.php
+
152
−
152
View file @
13c26a89
...
...
@@ -31,160 +31,160 @@
//Loads the require class
try
{
require_once
(
'core/class/class_functions.php'
);
require_once
(
'core/class/class_db.php'
);
require_once
(
'core/class/class_history.php'
);
//require_once('');
require_once
(
'core/class/class_functions.php'
);
require_once
(
'core/class/class_db.php'
);
require_once
(
'core/class/class_history.php'
);
//require_once('');
}
catch
(
Exception
$e
)
{
echo
$e
->
getMessage
()
.
' // '
;
echo
$e
->
getMessage
()
.
' // '
;
}
class
ExportControler
{
private
static
$db
;
private
static
$db2
;
private
static
$db3
;
private
static
$coll
;
private
static
$functions
;
private
static
$return_loadXMLConf
;
function
__construct
()
{
$this
->
coll
=
$_SESSION
[
'collection_id_choice'
];
$this
->
functions
=
new
functions
();
$this
->
return_loadXMLConf
=
$this
->
functions
->
object2array
(
$this
->
loadXMLConf
());
$this
->
db
=
new
dbquery
();
$this
->
db
->
connect
();
$this
->
db2
=
new
dbquery
();
$this
->
db2
->
connect
();
$this
->
db3
=
new
dbquery
();
$this
->
db3
->
connect
();
$this
->
export
();
}
private
function
export
()
{
$return_createQuery
=
$this
->
createQuery
();
//echo $return_createQuery;exit;
if
(
!
$this
->
db
->
query
(
$return_createQuery
,
true
))
{
$_SESSION
[
'error'
]
=
'Erreur SQL 1'
;
}
$resultQuery
[
0
]
=
$this
->
getHeaderOfCsv
();
$cpt
=
1
;
while
(
$return_dbQuery
=
$this
->
db
->
fetch_object
())
{
$return_dbQuery
->
subject
=
utf8_decode
(
$return_dbQuery
->
subject
);
$resultQuery
[
$cpt
]
=
$this
->
functions
->
object2array
(
$return_dbQuery
);
if
(
isset
(
$this
->
return_loadXMLConf
[
$this
->
coll
][
'FUNCTIONS'
][
'COPIES'
])
&&
!
empty
(
$this
->
return_loadXMLConf
[
$this
->
coll
][
'FUNCTIONS'
][
'COPIES'
]))
{
$resultQuery
[
$cpt
][
$this
->
return_loadXMLConf
[
$this
->
coll
][
'FUNCTIONS'
][
'COPIES'
]]
=
substr
(
$this
->
functions_copies
(
$return_dbQuery
->
res_id
),
0
,
-
2
);
}
$resultQuery
[
$cpt
][
'commentaire'
]
=
''
;
$cpt
++
;
}
$return_array2CSV
=
$this
->
array2CSV
(
$resultQuery
);
$_SESSION
[
'export'
][
'filename'
]
=
$return_array2CSV
;
}
private
function
createQuery
()
{
$query
=
'SELECT '
;
for
(
$i
=
0
;
$i
<
count
(
$this
->
return_loadXMLConf
[
$this
->
coll
][
'FIELD'
]);
$i
++
)
{
$query
.
=
$this
->
return_loadXMLConf
[
$this
->
coll
][
'FIELD'
][
$i
][
'DATABASE_FIELD'
];
if
(
$i
<>
(
count
(
$this
->
return_loadXMLConf
[
$this
->
coll
][
'FIELD'
])
-
1
))
{
$query
.
=
', '
;
}
}
$query
.
=
' '
.
substr
(
$_SESSION
[
'last_select_query'
],
stripos
(
$_SESSION
[
'last_select_query'
],
'FROM'
));
return
$query
;
}
private
function
array2CSV
(
$resultQuery
)
{
do
{
$csvName
=
$_SESSION
[
'user'
][
'UserId'
]
.
'-'
.
md5
(
date
(
'Y-m-d H:i:s'
))
.
'.csv'
;
if
(
isset
(
$pathToCsv
)
&&
!
empty
(
$pathToCsv
))
{
$csvName
=
$_SESSION
[
'user'
][
'UserId'
]
.
'-'
.
md5
(
$pathToCsv
)
.
'.csv'
;
}
$pathToCsv
=
$_SESSION
[
'config'
][
'tmppath'
]
.
$csvName
;
}
while
(
file_exists
(
$pathToCsv
));
$csvFile
=
fopen
(
$pathToCsv
,
'a+'
);
foreach
(
$resultQuery
as
$fields
)
{
fputcsv
(
$csvFile
,
$fields
,
';'
);
}
fclose
(
$csvFile
);
return
$csvName
;
}
private
function
getHeaderOfCsv
()
{
//echo '<pre>'.print_r($loadXMLConf, true).'</pre>';exit;
for
(
$i
=
0
;
$i
<
count
(
$this
->
return_loadXMLConf
[
$this
->
coll
][
'FIELD'
]);
$i
++
)
{
if
(
!
empty
(
$this
->
return_loadXMLConf
[
$this
->
coll
][
'FIELD'
][
$i
][
'LIBELLE'
]))
{
$tabToReturn
[
$i
]
=
$this
->
return_loadXMLConf
[
$this
->
coll
][
'FIELD'
][
$i
][
'LIBELLE'
];
}
else
{
$tabToReturn
[
$i
]
=
$this
->
return_loadXMLConf
[
$this
->
coll
][
'FIELD'
][
$i
][
'DATABASE_FIELD'
];
}
}
$temp
=
array_keys
(
$this
->
return_loadXMLConf
[
$this
->
coll
][
'FUNCTIONS'
]);
for
(
$k
=
0
;
$k
<
count
(
$temp
);
$k
++
)
{
$j
=
$i
+
$k
;
$tabToReturn
[
$j
]
=
$this
->
return_loadXMLConf
[
$this
->
coll
][
'FUNCTIONS'
][
$temp
[
$k
]];
}
if
(
$k
==
0
)
{
$j
=
$i
;
}
$tabToReturn
[
$j
+
1
]
=
$this
->
return_loadXMLConf
[
$this
->
coll
][
'FIXE'
];
return
$tabToReturn
;
}
private
function
loadXMLConf
()
{
$path
=
'apps/maarch_entreprise/xml/export.xml'
;
if
(
file_exists
(
'custom/'
.
$_SESSION
[
'custom_override_id'
]
.
'/apps/maarch_entreprise/xml/export.xml'
))
{
$path
=
'custom/'
.
$_SESSION
[
'custom_override_id'
]
.
'/apps/maarch_entreprise/xml/export.xml'
;
}
$exportConf
=
simplexml_load_file
(
$path
);
return
$exportConf
;
}
private
function
functions_copies
(
$res_id
)
{
$return_functionsCopies
=
''
;
$queryListinstance
=
"SELECT item_id, item_type FROM listinstance WHERE res_id = "
.
$res_id
.
" AND coll_id = '"
.
$this
->
coll
.
"' AND item_mode = 'cc'"
;
if
(
!
$this
->
db2
->
query
(
$queryListinstance
,
true
))
{
$_SESSION
[
'error'
]
=
'Erreur SQL 2'
;
}
$j
=
0
;
while
(
$return_dbQueryListinstance
=
$this
->
db2
->
fetch_object
())
{
if
(
$return_dbQueryListinstance
->
item_type
==
'user_id'
)
{
$queryUsersEntities
=
"SELECT entity_id FROM users_entities WHERE user_id = '"
.
$return_dbQueryListinstance
->
item_id
.
"' AND primary_entity = 'Y'"
;
if
(
!
$this
->
db3
->
query
(
$queryUsersEntities
,
true
))
{
$_SESSION
[
'error'
]
=
'Erreur SQL 3'
;
}
while
(
$return_dbQueryUsersEntities
=
$this
->
db3
->
fetch_object
())
{
$usersEntities
=
$return_dbQueryListinstance
->
item_id
.
' : '
.
$return_dbQueryUsersEntities
->
entity_id
;
}
}
else
{
$usersEntities
=
$return_dbQueryListinstance
->
item_id
;
}
$return_functionsCopies
.
=
$usersEntities
.
' | '
;
$j
++
;
}
return
$return_functionsCopies
;
}
{
private
static
$db
;
private
static
$db2
;
private
static
$db3
;
private
static
$coll
;
private
static
$functions
;
private
static
$return_loadXMLConf
;
function
__construct
()
{
$this
->
coll
=
$_SESSION
[
'collection_id_choice'
];
$this
->
functions
=
new
functions
();
$this
->
return_loadXMLConf
=
$this
->
functions
->
object2array
(
$this
->
loadXMLConf
());
$this
->
db
=
new
dbquery
();
$this
->
db
->
connect
();
$this
->
db2
=
new
dbquery
();
$this
->
db2
->
connect
();
$this
->
db3
=
new
dbquery
();
$this
->
db3
->
connect
();
$this
->
export
();
}
private
function
export
()
{
$return_createQuery
=
$this
->
createQuery
();
//echo $return_createQuery;exit;
if
(
!
$this
->
db
->
query
(
$return_createQuery
,
true
))
{
$_SESSION
[
'error'
]
=
'Erreur SQL 1'
;
}
$resultQuery
[
0
]
=
$this
->
getHeaderOfCsv
();
$cpt
=
1
;
while
(
$return_dbQuery
=
$this
->
db
->
fetch_object
())
{
$return_dbQuery
->
subject
=
utf8_decode
(
$return_dbQuery
->
subject
);
$resultQuery
[
$cpt
]
=
$this
->
functions
->
object2array
(
$return_dbQuery
);
if
(
isset
(
$this
->
return_loadXMLConf
[
$this
->
coll
][
'FUNCTIONS'
][
'COPIES'
])
&&
!
empty
(
$this
->
return_loadXMLConf
[
$this
->
coll
][
'FUNCTIONS'
][
'COPIES'
]))
{
$resultQuery
[
$cpt
][
$this
->
return_loadXMLConf
[
$this
->
coll
][
'FUNCTIONS'
][
'COPIES'
]]
=
substr
(
$this
->
functions_copies
(
$return_dbQuery
->
res_id
),
0
,
-
2
);
}
$resultQuery
[
$cpt
][
'commentaire'
]
=
''
;
$cpt
++
;
}
$return_array2CSV
=
$this
->
array2CSV
(
$resultQuery
);
$_SESSION
[
'export'
][
'filename'
]
=
$return_array2CSV
;
}
private
function
createQuery
()
{
$query
=
'SELECT '
;
for
(
$i
=
0
;
$i
<
count
(
$this
->
return_loadXMLConf
[
$this
->
coll
][
'FIELD'
]);
$i
++
)
{
$query
.
=
$this
->
return_loadXMLConf
[
$this
->
coll
][
'FIELD'
][
$i
][
'DATABASE_FIELD'
];
if
(
$i
<>
(
count
(
$this
->
return_loadXMLConf
[
$this
->
coll
][
'FIELD'
])
-
1
))
{
$query
.
=
', '
;
}
}
$query
.
=
' '
.
substr
(
$_SESSION
[
'last_select_query'
],
stripos
(
$_SESSION
[
'last_select_query'
],
'FROM'
));
return
$query
;
}
private
function
array2CSV
(
$resultQuery
)
{
do
{
$csvName
=
$_SESSION
[
'user'
][
'UserId'
]
.
'-'
.
md5
(
date
(
'Y-m-d H:i:s'
))
.
'.csv'
;
if
(
isset
(
$pathToCsv
)
&&
!
empty
(
$pathToCsv
))
{
$csvName
=
$_SESSION
[
'user'
][
'UserId'
]
.
'-'
.
md5
(
$pathToCsv
)
.
'.csv'
;
}
$pathToCsv
=
$_SESSION
[
'config'
][
'tmppath'
]
.
$csvName
;
}
while
(
file_exists
(
$pathToCsv
));
$csvFile
=
fopen
(
$pathToCsv
,
'a+'
);
foreach
(
$resultQuery
as
$fields
)
{
fputcsv
(
$csvFile
,
$fields
,
';'
);
}
fclose
(
$csvFile
);
return
$csvName
;
}
private
function
getHeaderOfCsv
()
{
//echo '<pre>'.print_r($loadXMLConf, true).'</pre>';exit;
for
(
$i
=
0
;
$i
<
count
(
$this
->
return_loadXMLConf
[
$this
->
coll
][
'FIELD'
]);
$i
++
)
{
if
(
!
empty
(
$this
->
return_loadXMLConf
[
$this
->
coll
][
'FIELD'
][
$i
][
'LIBELLE'
]))
{
$tabToReturn
[
$i
]
=
$this
->
return_loadXMLConf
[
$this
->
coll
][
'FIELD'
][
$i
][
'LIBELLE'
];
}
else
{
$tabToReturn
[
$i
]
=
$this
->
return_loadXMLConf
[
$this
->
coll
][
'FIELD'
][
$i
][
'DATABASE_FIELD'
];
}
}
$temp
=
array_keys
(
$this
->
return_loadXMLConf
[
$this
->
coll
][
'FUNCTIONS'
]);
for
(
$k
=
0
;
$k
<
count
(
$temp
);
$k
++
)
{
$j
=
$i
+
$k
;
$tabToReturn
[
$j
]
=
$this
->
return_loadXMLConf
[
$this
->
coll
][
'FUNCTIONS'
][
$temp
[
$k
]];
}
if
(
$k
==
0
)
{
$j
=
$i
;
}
$tabToReturn
[
$j
+
1
]
=
$this
->
return_loadXMLConf
[
$this
->
coll
][
'FIXE'
];
return
$tabToReturn
;
}
private
function
loadXMLConf
()
{
$path
=
'apps/maarch_entreprise/xml/export.xml'
;
if
(
file_exists
(
'custom/'
.
$_SESSION
[
'custom_override_id'
]
.
'/apps/maarch_entreprise/xml/export.xml'
))
{
$path
=
'custom/'
.
$_SESSION
[
'custom_override_id'
]
.
'/apps/maarch_entreprise/xml/export.xml'
;
}
$exportConf
=
simplexml_load_file
(
$path
);
return
$exportConf
;
}
private
function
functions_copies
(
$res_id
)
{
$return_functionsCopies
=
''
;
$queryListinstance
=
"SELECT item_id, item_type FROM listinstance WHERE res_id = "
.
$res_id
.
" AND coll_id = '"
.
$this
->
coll
.
"' AND item_mode = 'cc'"
;
if
(
!
$this
->
db2
->
query
(
$queryListinstance
,
true
))
{
$_SESSION
[
'error'
]
=
'Erreur SQL 2'
;
}
$j
=
0
;
while
(
$return_dbQueryListinstance
=
$this
->
db2
->
fetch_object
())
{
if
(
$return_dbQueryListinstance
->
item_type
==
'user_id'
)
{
$queryUsersEntities
=
"SELECT entity_id FROM users_entities WHERE user_id = '"
.
$return_dbQueryListinstance
->
item_id
.
"' AND primary_entity = 'Y'"
;
if
(
!
$this
->
db3
->
query
(
$queryUsersEntities
,
true
))
{
$_SESSION
[
'error'
]
=
'Erreur SQL 3'
;
}
while
(
$return_dbQueryUsersEntities
=
$this
->
db3
->
fetch_object
())
{
$usersEntities
=
$return_dbQueryListinstance
->
item_id
.
' : '
.
$return_dbQueryUsersEntities
->
entity_id
;
}
}
else
{
$usersEntities
=
$return_dbQueryListinstance
->
item_id
;
}
$return_functionsCopies
.
=
$usersEntities
.
' | '
;
$j
++
;
}
return
$return_functionsCopies
;
}
}
This diff is collapsed.
Click to expand it.
core/trunk/core/class/class_request.php
+
5
−
1
View file @
13c26a89
...
...
@@ -160,7 +160,11 @@ class request extends dbquery
}
$query
=
$this
->
limit_select
(
0
,
$limit
,
$field_string
,
$table_string
.
" "
.
$join
,
$where_string
,
$other
,
$dist
);
if
(
preg_match
(
'/res_view/i'
,
$query
))
{
$_SESSION
[
'last_select_query'
]
=
$query
;
}
$this
->
connect
();
$res_query
=
$this
->
query
(
$query
,
$catch_error
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment