13 |
pisoni |
1 |
<%doc>
|
|
|
2 |
# ---------------------------------------------------------------------- #
|
|
|
3 |
# Copyright: (C) 2002 Leader.IT S.r.l. <http://leader.it>
|
|
|
4 |
# Authors: Guido Brugnara <gdo@leader.it>
|
|
|
5 |
# Mario Claudio Pisoni <pisoni@leader.it>
|
|
|
6 |
#
|
|
|
7 |
# $Revision: 18 $
|
|
|
8 |
# ---------------------------------------------------------------------- #
|
|
|
9 |
</%doc>
|
|
|
10 |
<%perl>
|
|
|
11 |
# ==================================== Share functions =====================================================
|
|
|
12 |
# ============================================================================== Uses
|
|
|
13 |
use POSIX ":sys_wait_h";
|
|
|
14 |
use Symbol;
|
|
|
15 |
|
|
|
16 |
use IO::Select;
|
|
|
17 |
use IPC::Open3;
|
|
|
18 |
use IO::File;
|
|
|
19 |
|
|
|
20 |
use DBI;
|
|
|
21 |
|
|
|
22 |
# =============== check if two arrays has the same contents
|
|
|
23 |
sub sameContent($$){
|
|
|
24 |
my ($ref1, $ref2) = @_;
|
|
|
25 |
my $found = '';
|
|
|
26 |
|
|
|
27 |
if ( scalar(@$ref1) != scalar(@$ref2) ){
|
|
|
28 |
return($found);
|
|
|
29 |
}
|
|
|
30 |
|
|
|
31 |
foreach my $cur1 (@$ref1){
|
|
|
32 |
foreach my $cur2 (@$ref2){
|
|
|
33 |
if ($cur1 eq $cur2){
|
|
|
34 |
$found = 'TRUE';
|
|
|
35 |
last;
|
|
|
36 |
}
|
|
|
37 |
}
|
|
|
38 |
}
|
|
|
39 |
|
|
|
40 |
return($found);
|
|
|
41 |
}
|
|
|
42 |
|
|
|
43 |
# ============================================================================= writeMsg
|
|
|
44 |
sub writeMsg($$){
|
|
|
45 |
my($message, $curfunc) = @_;
|
|
|
46 |
|
|
|
47 |
my $LOGfile = '[[log_message_error_path]][[log_message_error_filename]]';
|
|
|
48 |
if(! $MAIN::log_cms){
|
|
|
49 |
`echo 'opening from run'>>[[log_message_error_path]][[log_message_error_filename]]`;
|
|
|
50 |
$MAIN::log_cms = new IO::File;
|
|
|
51 |
$MAIN::log_cms->open(">>$LOGfile") or die "Error opening file $LOGfile: $!";
|
|
|
52 |
$MAIN::log_cms->autoflush(1);
|
|
|
53 |
}
|
|
|
54 |
|
|
|
55 |
my($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime();
|
|
|
56 |
my $time = sprintf("%04d/%02d/%02d %02d:%02d:%02d", 1900+$year, $mon+1, $mday, $hour, $min, $sec);
|
|
|
57 |
|
|
|
58 |
print $MAIN::log_cms "$time>$curfunc:$message\n" or warn "on print file $LOGfile: $!";
|
|
|
59 |
# $MAIN::log_cms->close;
|
|
|
60 |
}
|
|
|
61 |
|
|
|
62 |
# ============================================================================== Esecuzione
|
|
|
63 |
sub Esecuzione{
|
|
|
64 |
# Esecuzione(5, 'ls', '-l');
|
|
|
65 |
my $timeout = shift;
|
|
|
66 |
my $input = gensym();
|
|
|
67 |
my $error = gensym();
|
|
|
68 |
my $output = gensym();
|
|
|
69 |
my($status, $out, $err);
|
|
|
70 |
|
|
|
71 |
# lancio il processo
|
|
|
72 |
my $pid = open3($input, $output, $error, @_);
|
|
|
73 |
my $sel = new IO::Select($output,$error);
|
|
|
74 |
LOOP: for(;;){
|
|
|
75 |
my @ready = $sel->can_read($timeout);
|
|
|
76 |
if(!@ready){
|
|
|
77 |
warn "Timeout read from host";
|
|
|
78 |
return (-1,$out,$err);
|
|
|
79 |
}
|
|
|
80 |
foreach my $h (@ready){
|
|
|
81 |
my $r = <$h>;
|
|
|
82 |
if($r){
|
|
|
83 |
if($h eq $output){
|
|
|
84 |
$out.=$r;
|
|
|
85 |
}elsif($h eq $error){
|
|
|
86 |
$err.=$r;
|
|
|
87 |
}else{
|
|
|
88 |
die "Handle $h unexpected";
|
|
|
89 |
}
|
|
|
90 |
}else{
|
|
|
91 |
$sel->remove($h);
|
|
|
92 |
if(!$sel->count()){
|
|
|
93 |
last LOOP;
|
|
|
94 |
}
|
|
|
95 |
}
|
|
|
96 |
}
|
|
|
97 |
}
|
|
|
98 |
if(waitpid($pid,&WNOHANG)){
|
|
|
99 |
$status = ($? & 0xff00)/256;
|
|
|
100 |
}else{
|
|
|
101 |
$status = 0;
|
|
|
102 |
}
|
|
|
103 |
return ($status, $out, $err);
|
|
|
104 |
}
|
|
|
105 |
|
|
|
106 |
# ============================================================================== checkExec
|
|
|
107 |
sub checkExec($$) {
|
|
|
108 |
my $caller = shift;
|
|
|
109 |
my($cmd) = @_;
|
|
|
110 |
my ($curfunc,$dbgerror,$dbginfo,$message) = ('100', ' 1:', ' 40:', '');
|
|
|
111 |
|
|
|
112 |
#### $s - status, $o - stdout, $r stderr
|
|
|
113 |
my($s, $o, $r) = Esecuzione(8, $cmd);
|
|
|
114 |
my $ret = '';
|
|
|
115 |
|
|
|
116 |
if ($s eq '0'){ ### No errors
|
|
|
117 |
chomp($o);
|
|
|
118 |
$ret = 'OK_'.$o;
|
|
|
119 |
$message = "in CheckExec, cmd= @_ out=$ret";
|
|
|
120 |
writeMsg($message, $dbginfo . $caller. $curfunc);
|
|
|
121 |
}elsif ($s eq '1'){ ### Error
|
|
|
122 |
$message = "Error on @_, status=$s, out=$o, err=$r";
|
|
|
123 |
writeMsg($message, $dbgerror . $caller. $curfunc);
|
|
|
124 |
}elsif ($s eq '-1'){ ### Time out
|
|
|
125 |
$message = "Time out on @_, status=$s, out=$o, err=$r";
|
|
|
126 |
writeMsg($message, $dbgerror . $caller. $curfunc);
|
|
|
127 |
}else{ ### Error Number > 1 on exit
|
|
|
128 |
$message = "Error on @_, status=$s, out=$o, err=$r";
|
|
|
129 |
writeMsg($message, $dbgerror . $caller. $curfunc);
|
|
|
130 |
}
|
|
|
131 |
|
|
|
132 |
return $ret;
|
|
|
133 |
}
|
|
|
134 |
|
|
|
135 |
sub rollbackCmd($$){
|
|
|
136 |
# ============================== exec all the command in the array of commands, BUT for the same argument!!!
|
|
|
137 |
my ($ref_cmd, $arg) = @_;
|
|
|
138 |
my ($curfunc,$dbgerror,$dbginfo,$message) = ('101', ' 1:', ' 40:', '');
|
|
|
139 |
|
|
|
140 |
my $wasError = '';
|
|
|
141 |
foreach my $curcmd (@$ref_cmd){
|
|
|
142 |
my $ret=checkExec($curfunc, "su1 cms_command $curcmd $arg");
|
|
|
143 |
if(! $ret ){
|
|
|
144 |
$wasError .= "Incorrect in $curcmd,";
|
|
|
145 |
}
|
|
|
146 |
}
|
|
|
147 |
return($wasError);
|
|
|
148 |
}
|
|
|
149 |
|
|
|
150 |
# ============================================================================== readFileIntoArray
|
|
|
151 |
sub readFileIntoArray($$$){
|
|
|
152 |
# ======= read a file, reverse if is needed and return N lines
|
|
|
153 |
my ($filename, $isReverse, $cantLines) = @_;
|
|
|
154 |
my ($curfunc,$dbgerror,$dbginfo,$message) = ('123', ' 1:', ' 50:', 'OK');
|
|
|
155 |
|
|
|
156 |
my $retArray;
|
|
|
157 |
|
|
|
158 |
if (! open(FH, '<', $filename)){
|
|
|
159 |
$retArray = "file:$filename, $!";
|
|
|
160 |
writeMsg("cant open file:$filename:, $!", $dbgerror . $curfunc);
|
|
|
161 |
return($retArray);
|
|
|
162 |
}
|
|
|
163 |
|
|
|
164 |
my $prevInputRecordSeparator = undef $/;
|
|
|
165 |
$retArray = <FH>;
|
|
|
166 |
# ### make a comment to turn on the ligths ' >
|
|
|
167 |
$/ = $prevInputRecordSeparator;
|
|
|
168 |
# $usrTraffic =~ s/\n//g;
|
|
|
169 |
close FH;
|
|
|
170 |
|
|
|
171 |
my @tmpArray = split "\n", $retArray;
|
|
|
172 |
|
|
|
173 |
my $limit;
|
|
|
174 |
if(! $cantLines){
|
|
|
175 |
$limit = $#tmpArray;
|
|
|
176 |
}else{
|
|
|
177 |
$limit = $cantLines;
|
|
|
178 |
}
|
|
|
179 |
# ### reverse the array, Im shure there is another way to doit ;)
|
|
|
180 |
my @tempA;
|
|
|
181 |
if($isReverse){
|
|
|
182 |
foreach my $line ( reverse @tmpArray){
|
|
|
183 |
if(! $limit){
|
|
|
184 |
last;
|
|
|
185 |
}
|
|
|
186 |
push @tempA, $line;
|
|
|
187 |
$limit --;
|
|
|
188 |
}
|
|
|
189 |
}else{
|
|
|
190 |
foreach my $line ( @tmpArray){
|
|
|
191 |
if(! $limit){
|
|
|
192 |
last;
|
|
|
193 |
}
|
|
|
194 |
push @tempA, $line;
|
|
|
195 |
$limit --;
|
|
|
196 |
}
|
|
|
197 |
}
|
|
|
198 |
$retArray = join "", @tempA;
|
|
|
199 |
|
|
|
200 |
return($retArray);
|
|
|
201 |
}
|
|
|
202 |
|
|
|
203 |
# ============================================================================== Proccess form fields
|
|
|
204 |
sub processPOST($$) {
|
|
|
205 |
my $function = shift;
|
|
|
206 |
my $ref_ARGS = shift;
|
|
|
207 |
|
|
|
208 |
my ($curfunc,$dbgerror,$dbginfo,$message) = ('122', ' 1:', ' 50:', 'OK');
|
|
|
209 |
my ($setfields, $setvalues) = ('','');
|
|
|
210 |
my $isFirstime = 1;
|
|
|
211 |
my @tmparr = [];
|
|
|
212 |
my $fieldsNotProcess = '';
|
|
|
213 |
|
|
|
214 |
foreach my $curkey (keys %$ref_ARGS){
|
|
|
215 |
if($curkey =~ /_HIDE_/){
|
|
|
216 |
next; ### skiping hidden field
|
|
|
217 |
}
|
|
|
218 |
if($curkey =~ /ROW./){
|
|
|
219 |
push(@tmparr, %$ref_ARGS->{$curkey});
|
|
|
220 |
next;
|
|
|
221 |
}
|
|
|
222 |
|
|
|
223 |
if($curkey =~ /FL\.(.+)/){
|
|
|
224 |
if($function eq 'update'){
|
|
|
225 |
if($1 =~ /_CHECK/){
|
|
|
226 |
# ============== is a buton Check =====
|
|
|
227 |
$setvalues = $curkey;
|
|
|
228 |
next;
|
|
|
229 |
}
|
|
|
230 |
if($1 =~ /_SELECT/){
|
|
|
231 |
# ============== is a Select Option =====
|
|
|
232 |
$setvalues = $curkey;
|
|
|
233 |
next;
|
|
|
234 |
}
|
|
|
235 |
if($isFirstime){
|
|
|
236 |
$setvalues = "$1='" . %$ref_ARGS->{$curkey} ."'";
|
|
|
237 |
$isFirstime = '';
|
|
|
238 |
next;
|
|
|
239 |
}
|
|
|
240 |
$setvalues = $setvalues . ", $1='" . %$ref_ARGS->{$curkey} ."'";
|
|
|
241 |
|
|
|
242 |
}else{
|
|
|
243 |
if($isFirstime){
|
|
|
244 |
$setfields .= "$1";
|
|
|
245 |
$setvalues .= "'" . %$ref_ARGS->{$curkey} . "'";
|
|
|
246 |
$isFirstime = '';
|
|
|
247 |
next;
|
|
|
248 |
}
|
|
|
249 |
$setfields .= ", $1";
|
|
|
250 |
$setvalues .= ", '" . %$ref_ARGS->{$curkey} . "'";
|
|
|
251 |
}
|
|
|
252 |
}
|
|
|
253 |
|
|
|
254 |
# propably there are some fields that are not trated here
|
|
|
255 |
$fieldsNotProcess .= "$curkey,";
|
|
|
256 |
|
|
|
257 |
}
|
|
|
258 |
|
|
|
259 |
if($fieldsNotProcess){
|
|
|
260 |
writeMsg("fieldsNotProcess:$fieldsNotProcess:", $dbginfo . $curfunc);
|
|
|
261 |
}
|
|
|
262 |
|
|
|
263 |
if($function eq 'update'){
|
|
|
264 |
return($setvalues);
|
|
|
265 |
}else{
|
|
|
266 |
return("($setfields) values ($setvalues)");
|
|
|
267 |
}
|
|
|
268 |
|
|
|
269 |
}
|
|
|
270 |
|
|
|
271 |
# ============================================================================== ADUClassListStr
|
|
|
272 |
sub ADUClassListStr($$$){
|
|
|
273 |
my ($function, $value, $newitemvalue) = @_;
|
|
|
274 |
my $retvalue = '';
|
|
|
275 |
my $found = '';
|
|
|
276 |
my $firstime = 'TRUE';
|
|
|
277 |
my ($newname, $newteacher, $newflag, $newcuraula, $newclasspersis) = split /:/, $newitemvalue;
|
|
|
278 |
my @classes = split /\s+/, $value;
|
|
|
279 |
#writeMsg("value=$value", "100");
|
|
|
280 |
my ($curfunc,$dbgerror,$dbginfo,$message) = ('123', ' 1:', ' 40:', '');
|
|
|
281 |
|
|
|
282 |
# ========================== Process all the active classes, [$classid:$teacherid:$flag] ...
|
|
|
283 |
foreach my $curclass ( @classes ){
|
|
|
284 |
my ($name, $teacher, $flag, $curaula, $classpersis) = split /:/, $curclass;
|
|
|
285 |
|
|
|
286 |
#writeMsg("curclass=$curclass", "100");
|
|
|
287 |
if( $name =~ m/$newname/ ){
|
|
|
288 |
$found = 'TRUE';
|
|
|
289 |
|
|
|
290 |
if($function eq 'ADD_FLAG' ){
|
|
|
291 |
if($flag !~ m/$newflag/){
|
|
|
292 |
$flag .= $newflag;
|
|
|
293 |
}
|
|
|
294 |
if($newteacher ne '_PREV_VALUE_'){
|
|
|
295 |
$teacher = $newteacher;
|
|
|
296 |
}
|
|
|
297 |
$curclass = "$name:$teacher:$flag:$curaula:$classpersis";
|
|
|
298 |
|
|
|
299 |
|
|
|
300 |
}elsif($function eq 'UPD_AULA'){
|
|
|
301 |
$curclass = "$name:$teacher:$flag:$newcuraula:$newclasspersis";
|
|
|
302 |
|
|
|
303 |
}elsif($function eq 'DELETE_FLAG'){
|
|
|
304 |
$flag =~ s/$newflag//;
|
|
|
305 |
if($newteacher ne '_PREV_VALUE_'){
|
|
|
306 |
$teacher =~ s/$newteacher//;
|
|
|
307 |
}
|
|
|
308 |
$curclass = "$name:$teacher:$flag:$curaula:$classpersis";
|
|
|
309 |
|
|
|
310 |
}elsif($function eq 'DELETE'){
|
|
|
311 |
$curclass = '';
|
|
|
312 |
|
|
|
313 |
}else{
|
|
|
314 |
$message = "Error: function:$function unknown\n";
|
|
|
315 |
writeMsg($message, $dbgerror . $curfunc);
|
|
|
316 |
}
|
|
|
317 |
}
|
|
|
318 |
|
|
|
319 |
if($firstime){
|
|
|
320 |
$retvalue = $curclass;
|
|
|
321 |
$firstime = '';
|
|
|
322 |
}else{
|
|
|
323 |
$retvalue .= ' ' . $curclass;
|
|
|
324 |
}
|
|
|
325 |
}
|
|
|
326 |
|
|
|
327 |
if(! $found ){
|
|
|
328 |
$message = "Error: flag:$newflag didn't find on keys\n";
|
|
|
329 |
writeMsg($message, $dbgerror . $curfunc);
|
|
|
330 |
$retvalue = undef;
|
|
|
331 |
}
|
|
|
332 |
|
|
|
333 |
return($retvalue);
|
|
|
334 |
}
|
|
|
335 |
|
|
|
336 |
|
|
|
337 |
# ========================================================================================
|
|
|
338 |
# ======================================= DB FUNCTIONS ===================================
|
|
|
339 |
# ========================================================================================
|
|
|
340 |
|
|
|
341 |
|
|
|
342 |
# ============================================================================== getDbConnect
|
|
|
343 |
sub getDbConnect($$){
|
|
|
344 |
my ($autoCommit,$raiseError) = @_;
|
|
|
345 |
my ($curfunc,$dbgerror,$dbginfo,$message) = ('102', ' 1:', ' 40:', 'OK');
|
|
|
346 |
|
|
|
347 |
if(!$autoCommit){
|
|
|
348 |
$autoCommit = 1;
|
|
|
349 |
}
|
|
|
350 |
if(!$raiseError){
|
|
|
351 |
$raiseError = 1;
|
|
|
352 |
}
|
|
|
353 |
my $dbh_cms = DBI->connect([[DB_StrConnect]]) or die "Cant connect dbh_cms;" . $DBI::strerr;
|
18 |
gdo |
354 |
DBI->trace(1, '[[log_trace_dbconnect]]');
|
|
|
355 |
# DBI->trace(1);
|
13 |
pisoni |
356 |
$dbh_cms->{RaiseError} = $raiseError;
|
|
|
357 |
$dbh_cms->{AutoCommit} = $autoCommit;
|
|
|
358 |
$dbh_cms->do('set DateStyle to SQL, EUROPEAN');
|
|
|
359 |
return($dbh_cms);
|
|
|
360 |
}
|
|
|
361 |
|
|
|
362 |
# ============================================================================== getField
|
|
|
363 |
sub getField($$$$){
|
|
|
364 |
my ($tbname, $field, $condition, $conditionvalue) = @_;
|
|
|
365 |
my $dbh = getDbConnect(1,1);
|
|
|
366 |
|
|
|
367 |
return(_getField($dbh, $tbname, $field, $condition, $conditionvalue));
|
|
|
368 |
}
|
|
|
369 |
# ============================================================================== _getField
|
|
|
370 |
sub _getField($$$$$){
|
|
|
371 |
my ($dbh, $tbname, $field, $condition, $conditionvalue) = @_;
|
|
|
372 |
my ($curfunc,$dbgerror,$dbginfo,$message) = ('103', ' 1:', ' 40:', 'OK');
|
|
|
373 |
my $value;
|
|
|
374 |
my $curSQL = "select $field from $tbname $condition";
|
|
|
375 |
|
|
|
376 |
my $sth = $dbh->prepare($curSQL);
|
|
|
377 |
my $ret = $sth->execute($conditionvalue);
|
|
|
378 |
if (! $ret){
|
|
|
379 |
$message = "error, on $curSQL\n; errstr:" . $dbh->errstr;
|
|
|
380 |
$value = $ret;
|
|
|
381 |
}else{
|
|
|
382 |
$value = $sth->fetchrow_array;
|
|
|
383 |
}
|
|
|
384 |
writeMsg($message, (($ret)? $dbginfo:$dbgerror) . $curfunc);
|
|
|
385 |
|
|
|
386 |
return($value);
|
|
|
387 |
}
|
|
|
388 |
|
|
|
389 |
# ============================================================================== updateField1
|
|
|
390 |
sub updateField1($$$$$){
|
|
|
391 |
my ($tbname, $field, $condition, $conditionvalue, $value) = @_;
|
|
|
392 |
my $set = "$field=?";
|
|
|
393 |
|
|
|
394 |
if($tbname eq 'keys'){
|
|
|
395 |
$set = "id=nextval('keys_id'), $field=?";
|
|
|
396 |
}
|
|
|
397 |
return(updateField($tbname, $set, $condition, $conditionvalue, $value));
|
|
|
398 |
}
|
|
|
399 |
|
|
|
400 |
# ============================================================================== updateField
|
|
|
401 |
sub updateField($$$$$){
|
|
|
402 |
my ($tbname, $set, $condition, $conditionvalue, $value) = @_;
|
|
|
403 |
my $dbh = getDbConnect(1,1);
|
|
|
404 |
|
|
|
405 |
return(_updateField($dbh, $tbname, $set, $condition, $conditionvalue, $value));
|
|
|
406 |
}
|
|
|
407 |
# ============================================================================== _updateField1
|
|
|
408 |
sub _updateField($$$$$$){
|
|
|
409 |
my ($dbh, $tbname, $set, $condition, $conditionvalue, $value) = @_;
|
|
|
410 |
my ($curfunc,$dbgerror,$dbginfo,$message) = ('104', ' 1:', ' 40:', 'OK');
|
|
|
411 |
|
|
|
412 |
my $curSQL = "update $tbname set $set $condition";
|
|
|
413 |
my $sth = $dbh->prepare($curSQL);
|
|
|
414 |
my $ret = $sth->execute($value, $conditionvalue);
|
|
|
415 |
if ($ret eq "0E0"){
|
|
|
416 |
$message = "error ret:$ret:, on $curSQL ($value, $conditionvalue); errstr:" . $dbh->errstr;
|
|
|
417 |
$ret = 0;
|
|
|
418 |
}
|
|
|
419 |
writeMsg($message, (($ret)? $dbginfo:$dbgerror) . $curfunc);
|
|
|
420 |
|
|
|
421 |
return($ret);
|
|
|
422 |
}
|
|
|
423 |
|
|
|
424 |
# ============================================================================== insertRecord
|
|
|
425 |
sub insertRecord($$){
|
|
|
426 |
my ($tbname, $condition) = @_;
|
|
|
427 |
my $dbh = getDbConnect(1,1);
|
|
|
428 |
|
|
|
429 |
return(_insertRecord($dbh, $tbname, $condition));
|
|
|
430 |
}
|
|
|
431 |
# ============================================================================== insertRecord
|
|
|
432 |
sub _insertRecord($$$){
|
|
|
433 |
my ($dbh, $tbname, $condition) = @_;
|
|
|
434 |
my ($curfunc,$dbgerror,$dbginfo,$message) = ('105', ' 1:', ' 40:', 'OK');
|
|
|
435 |
my $curSQL = "insert into $tbname $condition";
|
|
|
436 |
|
|
|
437 |
my $sth = $dbh->prepare($curSQL);
|
|
|
438 |
my $ret = $sth->execute();
|
|
|
439 |
if (! $ret){
|
|
|
440 |
$message = "error, on $curSQL\n; errstr:" . $dbh->errstr;
|
|
|
441 |
}
|
|
|
442 |
writeMsg($message, (($ret)? $dbginfo:$dbgerror) . $curfunc);
|
|
|
443 |
|
|
|
444 |
return($ret);
|
|
|
445 |
}
|
|
|
446 |
|
|
|
447 |
# ============================================================================== deleteRecord
|
|
|
448 |
sub deleteRecord($$$){
|
|
|
449 |
my ($tbname, $condition, $conditionvalue) = @_;
|
|
|
450 |
my $dbh = getDbConnect(1,1);
|
|
|
451 |
|
|
|
452 |
return(_deleteRecord($dbh, $tbname, $condition, $conditionvalue));
|
|
|
453 |
}
|
|
|
454 |
# ============================================================================== deleteRecord
|
|
|
455 |
sub _deleteRecord($$$$){
|
|
|
456 |
my ($dbh, $tbname, $condition, $conditionvalue) = @_;
|
|
|
457 |
my ($curfunc,$dbgerror,$dbginfo,$message) = ('106', ' 1:', ' 40:', 'OK');
|
|
|
458 |
my $curSQL = "delete from $tbname $condition";
|
|
|
459 |
|
|
|
460 |
my $sth = $dbh->prepare($curSQL);
|
|
|
461 |
my $ret = $sth->execute($conditionvalue);
|
|
|
462 |
if (! $ret){
|
|
|
463 |
$message = "error, on $curSQL\n; errstr:" . $dbh->errstr;
|
|
|
464 |
}
|
|
|
465 |
writeMsg($message, (($ret)? $dbginfo:$dbgerror) . $curfunc);
|
|
|
466 |
|
|
|
467 |
return($ret);
|
|
|
468 |
}
|
|
|
469 |
|
|
|
470 |
# ============================================================================== modifyFieldDataFunction
|
|
|
471 |
sub modifyFieldDataFunction($$$){
|
|
|
472 |
my ($value, $function, $functionargs) = @_;
|
|
|
473 |
my ($curfunc,$dbgerror,$dbginfo,$message) = ('34b', ' 1:', ' 40:', '');
|
|
|
474 |
my $newvalue;
|
|
|
475 |
|
|
|
476 |
#writeMsg("MAPI fargs=$functionargs=", $dbginfo . $curfunc);
|
|
|
477 |
#writeMsg("MAPI value=$value=", $dbginfo . $curfunc);
|
|
|
478 |
if($function eq 'deleteClass'){
|
|
|
479 |
my $classid = $functionargs;
|
|
|
480 |
$newvalue = ADUClassListStr('DELETE', $value, "$classid:_PREV_VALUE_:_PREV_VALUE:_PREV_VALUE_:_PREV_VALUE");
|
|
|
481 |
|
|
|
482 |
}elsif($function eq 'insertVipUsr'){
|
|
|
483 |
my $usrid = $functionargs;
|
|
|
484 |
$newvalue = $value;
|
|
|
485 |
if($value !~ m/$usrid/){
|
|
|
486 |
$newvalue = $value . " $usrid";
|
|
|
487 |
}
|
|
|
488 |
}elsif($function eq 'deleteVipUsr'){
|
|
|
489 |
my $usrid = $functionargs;
|
|
|
490 |
$newvalue = $value;
|
|
|
491 |
if($value =~ m/$usrid/){
|
|
|
492 |
$newvalue =~ s/$usrid//;
|
|
|
493 |
}
|
|
|
494 |
|
|
|
495 |
}elsif($function eq 'deleteFM'){
|
|
|
496 |
my $fm = $functionargs;
|
|
|
497 |
$newvalue = $value;
|
|
|
498 |
if($value =~ m/$fm/){
|
|
|
499 |
$newvalue =~ s/\s*$fm//;
|
|
|
500 |
}
|
|
|
501 |
}elsif($function eq 'insertFM'){
|
|
|
502 |
chomp($value);
|
|
|
503 |
$newvalue = $value . "$functionargs";
|
|
|
504 |
|
|
|
505 |
}elsif($function eq 'insertClass'){
|
|
|
506 |
chomp($value);
|
|
|
507 |
my $tmpargs = $functionargs;
|
|
|
508 |
if($functionargs =~ m/_BLANK_/){
|
|
|
509 |
$tmpargs =~ s/_BLANK_//;
|
|
|
510 |
#writeMsg("MAPI tmpargs=$tmpargs=", $dbginfo . $curfunc);
|
|
|
511 |
}
|
|
|
512 |
$newvalue = $value . " $tmpargs";
|
|
|
513 |
|
|
|
514 |
}elsif($function eq 'updateClass'){
|
|
|
515 |
$newvalue = $value . " $functionargs";
|
|
|
516 |
|
|
|
517 |
|
|
|
518 |
}elsif($function eq 'updateClassAula'){
|
|
|
519 |
my ($classid, $status, $newflag, $curaula, $classpersis) = split /:/, $functionargs;
|
|
|
520 |
if($classpersis =~ m/_BLANK_/){
|
|
|
521 |
$classpersis =~ s/_BLANK_//;
|
|
|
522 |
}
|
|
|
523 |
$newvalue = ADUClassListStr('UPD_AULA', $value, "$classid:_PREV_VALUE_:_PREV_VALUE_:$curaula:$classpersis");
|
|
|
524 |
|
|
|
525 |
|
|
|
526 |
}elsif($function eq 'updateClassFlag'){
|
|
|
527 |
my ($classid, $status, $newflag, $curaula, $classpersis) = split /:/, $functionargs;
|
|
|
528 |
#$m->out(Dumper($functionargs));
|
|
|
529 |
if($status =~ m/[[class_status_active]]/ ){
|
|
|
530 |
$newvalue = ADUClassListStr('ADD_FLAG', $value, "$classid:_PREV_VALUE_:$newflag:_PREV_VALUE_:_PREV_VALUE");
|
|
|
531 |
}else{
|
|
|
532 |
$newvalue = ADUClassListStr('DELETE_FLAG', $value, "$classid:_PREV_VALUE_:$newflag:_PREV_VALUE_:_PREV_VALUE");
|
|
|
533 |
}
|
|
|
534 |
|
|
|
535 |
# =========== used by class ==========
|
|
|
536 |
}elsif($function eq 'OFF'){
|
|
|
537 |
$newvalue = $value;
|
|
|
538 |
if($value =~ m/$functionargs/){
|
|
|
539 |
$newvalue =~ s/$functionargs//;
|
|
|
540 |
}
|
|
|
541 |
}elsif($function eq 'ON'){
|
|
|
542 |
$newvalue = $value . "$functionargs";
|
|
|
543 |
|
|
|
544 |
}else{
|
|
|
545 |
writeMsg("Error:rich case default on $function", $dbgerror . $curfunc);
|
|
|
546 |
}
|
|
|
547 |
|
|
|
548 |
|
|
|
549 |
return($newvalue);
|
|
|
550 |
}
|
|
|
551 |
|
|
|
552 |
# ============================================================================== updateDbField
|
|
|
553 |
sub modifyFieldData($$$$$$){
|
|
|
554 |
my ($tablename, $field, $condition, $conditionvalue, $function, $functionargs) = @_;
|
|
|
555 |
my ($curfunc,$dbgerror,$dbginfo,$message) = ('34b', ' 1:', ' 40:', '');
|
|
|
556 |
my $dbh = getDbConnect(1,1);
|
|
|
557 |
|
|
|
558 |
# ===================================================================== Begin Transaction
|
|
|
559 |
$dbh->begin_work or writeMsg("cant begin trans".$dbh->errstr, $dbgerror . $curfunc);
|
|
|
560 |
my $ret = _modifyFieldData($dbh, $tablename, $field, $condition, $conditionvalue, $function, $functionargs);
|
|
|
561 |
if(! $dbh->commit){
|
|
|
562 |
$dbh->rollback or writeMsg("cant commit".$dbh->errstr, $dbgerror . $curfunc);
|
|
|
563 |
writeMsg("Cant commit ".$dbh->errstr, $dbgerror . $curfunc);
|
|
|
564 |
}else{
|
|
|
565 |
writeMsg("OK", $dbginfo . $curfunc);
|
|
|
566 |
}
|
|
|
567 |
return($ret);
|
|
|
568 |
}
|
|
|
569 |
# ============================================================================== updateDbField
|
|
|
570 |
sub _modifyFieldData($$$$$$$){
|
|
|
571 |
my ($dbh, $tablename, $field, $condition, $conditionvalue, $function, $functionargs) = @_;
|
|
|
572 |
my ($sth, $ret, $curSQL);
|
|
|
573 |
my ($key, $value, $newvalue);
|
|
|
574 |
my ($curfunc,$dbgerror,$dbginfo,$message) = ('34', ' 1:', ' 40:', '');
|
|
|
575 |
|
|
|
576 |
# ==================================================== Get the value to update
|
|
|
577 |
$curSQL = "select $field from $tablename $condition";
|
|
|
578 |
$sth = $dbh->prepare($curSQL);
|
|
|
579 |
$ret = $sth->execute($conditionvalue);
|
|
|
580 |
if (! $ret){
|
|
|
581 |
$message = "error, on $curSQL\n; errstr:" . $dbh->errstr;
|
|
|
582 |
writeMsg($message, $dbgerror . $curfunc);
|
|
|
583 |
}
|
|
|
584 |
$value = $sth->fetchrow_array;
|
|
|
585 |
|
|
|
586 |
# ==================================================== Process the value with function
|
|
|
587 |
$newvalue = modifyFieldDataFunction($value, $function, $functionargs);
|
|
|
588 |
if($newvalue eq undef){
|
|
|
589 |
return(0);
|
|
|
590 |
}
|
|
|
591 |
|
|
|
592 |
# ==================================================== Process the value with function
|
|
|
593 |
if($tablename eq 'keys'){
|
|
|
594 |
$curSQL = "update $tablename set id=nextval('keys_id'), $field=? $condition";
|
|
|
595 |
}else{
|
|
|
596 |
$curSQL = "update $tablename set $field=? $condition";
|
|
|
597 |
}
|
|
|
598 |
#$m->out( $curSQL);
|
|
|
599 |
$sth = $dbh->prepare($curSQL);
|
|
|
600 |
$ret = $sth->execute($newvalue, $conditionvalue);
|
|
|
601 |
if (! $ret){
|
|
|
602 |
$message = "error, on $curSQL\n; errstr:" . $dbh->errstr;
|
|
|
603 |
writeMsg($message, $dbgerror . $curfunc);
|
|
|
604 |
}
|
|
|
605 |
return($ret);
|
|
|
606 |
}
|
|
|
607 |
|
|
|
608 |
|
|
|
609 |
|
|
|
610 |
|
|
|
611 |
# ============================================================================== getUsrConnectInfo
|
|
|
612 |
sub getUsrConnectInfo($){
|
|
|
613 |
my ($field) = @_;
|
|
|
614 |
my $dbh = getDbConnect(1,1);
|
|
|
615 |
|
|
|
616 |
return(_getUsrConnectInfo($dbh, $field));
|
|
|
617 |
}
|
|
|
618 |
# ============================================================================== getUsrConnectInfo
|
|
|
619 |
sub _getUsrConnectInfo($$){
|
|
|
620 |
my ($dbh, $field) = @_;
|
|
|
621 |
my ($curfunc,$dbgerror,$dbginfo,$message) = ('107', ' 1:', ' 40:', 'OK');
|
|
|
622 |
|
|
|
623 |
my ($ret, $remoteIp);
|
|
|
624 |
|
|
|
625 |
if(%ENV->{'HTTP_X_FORWARDED_FOR'}){
|
|
|
626 |
$remoteIp= %ENV->{'HTTP_X_FORWARDED_FOR'};
|
|
|
627 |
}else{
|
|
|
628 |
$remoteIp= %ENV->{'REMOTE_ADDR'};
|
|
|
629 |
}
|
|
|
630 |
|
|
|
631 |
if($field eq 'profile'){
|
|
|
632 |
my $sth = $dbh->prepare_cached(<<SQL);
|
|
|
633 |
select profile from usr, classlayout where classlayout.usrid = usr.id and classlayout.pcip=?
|
|
|
634 |
SQL
|
|
|
635 |
|
|
|
636 |
# my $profile;
|
|
|
637 |
# $sth->bind_columns(undef, \$profile);
|
|
|
638 |
$sth->execute($remoteIp);
|
|
|
639 |
# $sth->fetch;
|
|
|
640 |
# $ret = $profile;
|
|
|
641 |
($ret) = $sth->fetchrow_array;
|
|
|
642 |
|
|
|
643 |
|
|
|
644 |
}else{
|
|
|
645 |
my $cmd = " select $field";
|
|
|
646 |
my $from = ' from usr, classlayout';
|
|
|
647 |
my $where = ' where classlayout.usrid = usr.id and classlayout.pcip=?';
|
|
|
648 |
|
|
|
649 |
my $curSQL = $cmd . $from . $where;
|
|
|
650 |
my $sth = $dbh->prepare($curSQL);
|
|
|
651 |
if(! $sth->execute($remoteIp) ){
|
|
|
652 |
$message = "error, on $curSQL\n; errstr:" . $dbh->errstr;
|
|
|
653 |
writeMsg($message, (($ret)? $dbginfo:$dbgerror) . $curfunc);
|
|
|
654 |
}
|
|
|
655 |
($ret) = $sth->fetchrow_array;
|
|
|
656 |
}
|
|
|
657 |
return($ret);
|
|
|
658 |
|
|
|
659 |
}
|
|
|
660 |
|
|
|
661 |
|
|
|
662 |
# ============================================================================== getEnableStudentOfClass
|
|
|
663 |
sub getStudentOfClass($$){
|
|
|
664 |
my ($classid, $reason) = @_;
|
|
|
665 |
my $dbh = getDbConnect(1,1);
|
|
|
666 |
|
|
|
667 |
return(_getStudentOfClass($dbh, $classid, $reason));
|
|
|
668 |
}
|
|
|
669 |
# ============================================================================== getEnableStudentOfClass
|
|
|
670 |
sub _getStudentOfClass($$$){
|
|
|
671 |
my ($dbh, $classid, $reason) = @_;
|
|
|
672 |
my ($sth, $ret, $curSQL);
|
|
|
673 |
my ($curfunc,$dbgerror,$dbginfo,$message) = ('36', ' 1:', ' 40:', 'OK');
|
|
|
674 |
|
|
|
675 |
if($reason eq '4share'){
|
|
|
676 |
$curSQL = "select usrid from usrclass, usr where classid='$classid' and usrclass.profile='[[usr_profile_student]]' and usrclass.permision like '%[[usr_permision_SH]]%' and usrid=usr.id and usr.profile='[[usr_profile_student]]'";
|
|
|
677 |
}elsif($reason eq '4web'){
|
|
|
678 |
$curSQL = "select usrid from usrclass where classid='$classid' and profile='[[usr_profile_student]]' and permision like '%[[usr_permision_WW]]%' ";
|
|
|
679 |
}elsif($reason eq '4all'){
|
|
|
680 |
$curSQL = "select usrid from usrclass where classid='$classid' and profile='[[usr_profile_student]]'";
|
|
|
681 |
}else{
|
|
|
682 |
writeMsg("in Otherwise :$reason:", $dbgerror . $curfunc);
|
|
|
683 |
}
|
|
|
684 |
|
|
|
685 |
my $ref_usrid = $dbh->selectall_arrayref($curSQL);
|
|
|
686 |
if (! $ref_usrid){
|
|
|
687 |
my $message = "error, on $curSQL\n; errstr:" . $dbh->errstr;
|
|
|
688 |
writeMsg($message, $curfunc);
|
|
|
689 |
}else{
|
|
|
690 |
writeMsg("OK", $dbginfo . $curfunc);
|
|
|
691 |
}
|
|
|
692 |
|
|
|
693 |
my $listusr = '';
|
|
|
694 |
foreach my $curusr ( @$ref_usrid ){
|
|
|
695 |
$listusr .= ' ' . $curusr->[0];
|
|
|
696 |
}
|
|
|
697 |
|
|
|
698 |
return($listusr);
|
|
|
699 |
}
|
|
|
700 |
|
|
|
701 |
|
|
|
702 |
|
|
|
703 |
# ==================================== End Share functions =================================================
|
|
|
704 |
</%perl>
|
|
|
705 |
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
|
706 |
<html>
|
|
|
707 |
<head>
|
|
|
708 |
<META HTTP-EQUIV="content-type" CONTENT="text/html; charset=ISO-8859-15">
|
|
|
709 |
<META HTTP-EQUIV="Expires" CONTENT="now">
|
|
|
710 |
<title>
|
|
|
711 |
<& SELF:title &>
|
|
|
712 |
</title>
|
|
|
713 |
<link rel="stylesheet" href="/cms/include/styles.css?Rel=001" type="text/css">
|
|
|
714 |
</head>
|
|
|
715 |
%# <BODY BGCOLOR="<% $color %>">
|
|
|
716 |
|
|
|
717 |
<% $m->call_next %>
|
|
|
718 |
<& .footer &>
|
|
|
719 |
<%method title>
|
|
|
720 |
CMS (Classroom Management System) by Leader.IT S.r.l.
|
|
|
721 |
</%method>
|
|
|
722 |
<%init>
|
|
|
723 |
my $color = "#f1edd3";
|
|
|
724 |
$r->headers_out->add('Expires' => 'now');
|
|
|
725 |
$r->headers_out->add('Content-Language' => 'it_IT');
|
|
|
726 |
</%init>
|