Subversion Repositories cms

Rev

Rev 14 | Blame | Compare with Previous | Last modification | View Log | RSS feed

%# =============================================  Start of Embedded Components ===========================
%#
%#  -----------------------------------------------------------------------------------------------------
%#  - _label component return a TD with the traduction of a field, call a component that have some fields defined
<%def _label>
<td colspan="1" class="InputLabel"><% $m->comp('.thead.columnSettings', curfield => $field, cursetting => 'traduction') %></td>
<%args>
  $field
</%args>
</%def>
%#  -----------------------------------------------------------------------------------------------------
%#  - _input component return input object, if is a check return a hidden with some information on the name attribute
<%def _input>
<%perl>
# ==========================================================================================================
# This object creates a hidden input field to send the information of the check input field clicked
# In the hidden field, the name gives the information of the switch (On-Off) and the behaviour(Match-Assign)
# The value of the hidden is always the value4check (that initialize the value of the check)
# property name of the input field is: FL.fieldname[:ID.id][:TY.typefield[:AC.actionfield]][:TB.tablename]
# =========================================================================================================
  if($param{'type'} eq 'checkbox'){
    my $fieldname;
    if($param{'behaviour'} eq 'match'){
      $fieldname = "FL.$param{'dbfield'}:ID.$param{'id'}:TY._CHECK_MATCH";
    }elsif($param{'behaviour'} eq 'assign'){
      $fieldname = "FL.$param{'dbfield'}:ID.$param{'id'}:TY._CHECK";
    }else{
      writeMsg("undef function for behaviour:$param{'behaviour'}", 'class.html');
    }
    my $check = '';
    if($param{'value'} =~ /$param{'value4check'}/){
      $check = 'CHECKED';
      $fieldname .= ':AC.OFF';
    }else{
      $check = '';
      $fieldname .= ':AC.ON';
    }
    my $onclick = "checksubmit(this, '$fieldname')";
</%perl>
     <input type="checkbox" id="CKECK_<% $param{'id'} %>" class="" onClick="<% $onclick %>" <% $check %> ><% $param{'label'} %>
     <input type="hidden" id="<% $fieldname %>" value="<% $param{'value4check'} %>"  >
%  }else{
%    writeMsg("undef function for type:$param{'type'}", 'class.html');
%  }
<%args>
  %param
</%args>
</%def>
%# =============================================  End of Embedded Components ===========================
%#
%#
%#
%# =============================================  Start of HTML page ===================================
<script language="JavaScript">
function checksubmit(cb, idname)
{
  var re = /ID\.<% $hashChecks{'fm'}{'id'} %>/;
  if(re.test(idname)){
    var objclass = document.getElementById("CKECK_<% $hashChecks{'class'}{'id'} %>");
    if(!objclass.checked){
      alert("<% $hashDescription{'alertfm'} %>");
      cb.checked = false;
      return;
    }
  }
  re = /_CHECK/;
  if(re.test(idname)){
    cb.disabled=true;
  }
  var obj = document.getElementById(idname);
  obj.name = idname;
  form1.submit();
}
</script>
<form name="form1" action="class.html?wh=<% $classid %>" method="post">
<table cellspacing="0" cellpadding="2" border="0" width="100%">
 <thead class="tablepeople">
        <td colspan="2"><% $hashDescription{'tableTitle'} %></td>
 </thead>
 <tbody>
  <tr>
   <td colspan="*">&nbsp;</td>
  </tr>
  <tr>
        <td class=tablepeople width="*"><% $hashDescription{'class'} %></td>
        <td class=tablepeople width="1"><% $m->comp('_input', param => $hashChecks{'class'}) %></td>
  </tr>
  <tr>
        <td class=tablepeople width="*"><% $hashDescription{'share'} %></td>
        <td class=tablepeople width="1"><% $m->comp('_input', param => $hashChecks{'share'}) %></td>
  </tr>
% if($permision =~ /[[class_permision_YI]]/){
% if($teacherpermision =~ /[[usr_permision_WW]]/){    ### added 030203
  <tr>
        <td class=tablepeople width="*"><% $hashDescription{'web'} %></td>
        <td class=tablepeople width="1"><% $m->comp('_input', param => $hashChecks{'web'}) %></td>
  </tr>
  <tr>
        <td class=tablepeople width="*"><% $hashDescription{'fm'} %></td>
        <td class=tablepeople width="1"><% $m->comp('_input', param => $hashChecks{'fm'}) %></td>
  </tr>
% }   ### added 030203
% }
  <tr>
        <td class=tablepeople width="*"><% $hashDescription{'simulimp'} %></td>
%  if($status eq '[[class_status_active]]'){            ### added 030206
        <td class=tablepeople width="10%" >
%    if($simulvalue eq ''){ $simulvalue= '[[FM_controlclass_simulNessuna_IT]]';}
                <% $simulvalue %>
  </td>
%  }else{
        <td class=tablepeople width="10%">
%    my $fieldname = "FL.$simulfield:TY._SELECT";
     <select id="<% $fieldname %>" class="InputText" <% $simulvalue %> onChange="checksubmit(this, '<% $fieldname %>')">
        <option <%($simulvalue eq '') ? 'SELECTED':'' %> value="" >[[FM_controlclass_simulNessuna_IT]]
%     foreach my $curitem (@$classroom_ref){
        <option <%($simulvalue eq $curitem->[0]) ? 'SELECTED':'' %> value="<% $curitem->[0] %>" ><% $curitem->[0] %>
%     }
  </td>
%  }
  </tr>
 </tbody>
</table>
</form>
%# =============================================  End of HTML page ===================================
<%method title>
  [[FM_controlclass_windowTitle_IT]]
</%method>
<%args>
  $wh
</%args>
<%init>
  my $classid = $wh;
  my ($curfunc,$dbgerror,$dbginfo,$message)  = ('class', ' 1:', ' 30:', '');

  my $simulfield = '[[TB_class_SqlAs_classroompersistent]]';
#use Data::Dumper;
#$m->out(Dumper(%ARGS)); #$m->out("\n"); #$m->out(%ENV); #$m->out("\n");


# ============================================== Process Request POST ====================== 
  my $ret;
  if($ENV{'REQUEST_METHOD'} eq 'POST'){


#   put all the info of the check in a hash ==============
    my $keyfield = processPOST('update', \%ARGS);
#$m->out("keyfield:$keyfield:");
    my $keyvalue = $ARGS{$keyfield};
    my @arrField = split /:/, $keyfield;
    my %hashField;
    my ($tmp1, $tmp2);
    foreach my $curitem (@arrField) { 
      ($tmp1, $tmp2) = split /\./, $curitem;
      $hashField{$tmp1} = $tmp2;
    } 

#   Process the check regarding its ID ==============
    if($hashField{'TY'} =~ /_CHECK_MATCH/ ){   ### we have to modify a part of the field of the record

      if($hashField{'ID'} eq 'share'){   #-------------------------------------------------------------
        my $cms_action = ($hashField{'AC'} =~ /ON/) ? 'enableshare':'disableshare';
        writeMsg("$hashField{'ID'} = $hashField{'AC'}", $dbginfo . $curfunc);
        modifyFieldData('class', $hashField{'FL'}, 'where id=?', $classid, $hashField{'AC'}, $keyvalue);
        checkExec($curfunc, "su1 cms_command $cms_action $classid");

      }elsif($hashField{'ID'} eq 'web'){  #-------------------------------------------------------------
        my $listusr = ($hashField{'AC'} =~ /ON/) ? getStudentOfClass($classid, '4web'):'';
        writeMsg("$hashField{'ID'} = $hashField{'AC'}", $dbginfo . $curfunc);
        modifyFieldData('class', $hashField{'FL'}, 'where id=?', $classid, $hashField{'AC'}, $keyvalue);
#        if($listusr){
          $ret = updateField('keys', "id=nextval('keys_id'), value=?", 'where key=?', "Class_$classid", $listusr);
          if($ret){
            checkExec($curfunc, "su1 HUP_squid_redirect");
          }
#        }

      }elsif($hashField{'ID'} eq 'fm'){   #-------------------------------------------------------------
        writeMsg("$hashField{'ID'} = $hashField{'AC'}", $dbginfo . $curfunc);
        my $dbh = getDbConnect(1,1);
        my ($sitefm, $status, $keyfm);
        if($hashField{'AC'} =~ /ON/){
          $sitefm = getField('class', 'sitefm', 'where id=?', $classid);
          $status = '[[class_status_active]]';
        }else{
          $sitefm = '';
          $status = '[[class_status_suspend]]';
          ### saveFM($classid);  #set sitefm field = FM_$classid KEYS field
            $keyfm = getField('keys', 'value', 'where key=?', "FM_$classid");
            if(!$keyfm){
              writeMsg("FM_$classid field from keys return :$keyfm:", $dbginfo . $curfunc);
            }
        }
        $dbh->begin_work or writeMsg("Error:$hashField{'ID'}, cant begin_work", $dbgerror . $curfunc);
        eval{
          if($hashField{'AC'} !~ /ON/){
            _updateField($dbh, 'class', 'sitefm=?', 'where id=?', $classid, $keyfm) or die;
          }
          _updateField($dbh, 'keys', "id=nextval('keys_id'), value=?", 'where key=?', "FM_$classid", $sitefm) or die;
          _modifyFieldData($dbh, 'class', $hashField{'FL'}, 'where id=?', $classid, $hashField{'AC'}, $keyvalue) or die;

          # =================== add or delete 'FM' on ClassList keys tag, depending of $status
          _modifyFieldData($dbh, 'keys','value','where key=?',"ClassList",'updateClassFlag',"$classid:$status:FM:_BLANK_:_BLANK_") or die;  ###030128   
        };
        if($@){
          $dbh->rollback or writeMsg("cant rollback".$dbh->errstr, $dbgerror . $curfunc);
          writeMsg("rollback because error in eval; ".$@.$dbh->errstr, $dbginfo . $curfunc);
        }else{
          if(! $dbh->commit){
            writeMsg("error commit".$@.$dbh->errstr, $dbgerror . $curfunc);
          }else{
            checkExec($curfunc, "su1 HUP_squid_redirect");
          }
        }


      }else{
        writeMsg("Error:rich case default on $hashField{'ID'}", $dbgerror . $curfunc);
      }


    }elsif($hashField{'TY'} =~ /_CHECK/){
#     we have to assign the field of the record
      if($hashField{'ID'} eq 'class'){   #------------------------------------------------------------- 
        my $remoteIp= '';
        my $cmd_action;
        my $rooms = '';
        writeMsg("$hashField{'ID'} = $hashField{'AC'}", $dbginfo . $curfunc);
        my $dbh = getDbConnect(1,1);
        my $listusr4share = _getStudentOfClass($dbh, $classid, '4share');
        my $classpermision = _getField($dbh, 'class', 'permision', 'where id=?', $classid);

        if ($hashField{'AC'} =~ /ON/){
          if(%ENV->{'HTTP_X_FORWARDED_FOR'}){
            $remoteIp= %ENV->{'HTTP_X_FORWARDED_FOR'};
          }else{
            $remoteIp= %ENV->{'REMOTE_ADDR'};
          }
          $cmd_action = 'enableclass';

                my $curaula  = _getField($dbh, 'classlayout', 'id', 'where pcip=?', $remoteIp);                                 ###030128
          my $classpersis = _getField($dbh, 'class', 'classroompersistent', 'where id=?', $classid); ###030128
                                  $rooms = "-room $curaula";
                                        $rooms .= ($classpersis) ? ' -room ' . $classpersis : '';

          if($classpermision =~ m/[[class_permision_YI]]/ ){
            my $listusr4web = '';
            if($classpermision =~ m/[[usr_permision_WW]]/){
              $listusr4web = _getStudentOfClass($dbh, $classid, '4web');
            }
            my $teacherid = _getUsrConnectInfo($dbh, 'usrid');
            my $sitefm   = _getField($dbh, 'class', 'sitefm', 'where id=?', $classid);
            my $siteok   = _getField($dbh, 'class', 'siteok', 'where id=?', $classid);
            my $sitebad  = _getField($dbh, 'class', 'sitebad', 'where id=?', $classid);
            $keyvalue = '[[class_status_active]]';

#           ###--- insertIntoKeys($classid, $teacherid);   #new KEYS records: ClassList,Class,OkAuth,NoAuth,FM ---
            $dbh->begin_work or writeMsg("Error:$hashField{'ID'}, cant begin_work", $dbgerror . $curfunc);
            eval{
              _modifyFieldData($dbh, 'keys', 'value', 'where key=?', 'ClassList', 'insertClass', "$classid:$teacherid:_BLANK_:$curaula:$classpersis");  ###030128
              _insertRecord($dbh, 'keys', "(id,key,value) values (nextval('keys_id'), 'Class_$classid',  '$listusr4web')");
              _insertRecord($dbh, 'keys', "(id,key,value) values (nextval('keys_id'), 'FM_$classid',     '$sitefm')");
              _insertRecord($dbh, 'keys', "(id,key,value) values (nextval('keys_id'), 'OkAuth_$classid', '$siteok')");
              _insertRecord($dbh, 'keys', "(id,key,value) values (nextval('keys_id'), 'NoAuth_$classid', '$sitebad')");
              _updateField($dbh, 'class', "status='$keyvalue', ipteacher=?", 'where id=?', $classid, $remoteIp);
            };
          }else{
#           ------ Only Allow login and Shares resouces -------
            $dbh->begin_work or writeMsg("Error:$hashField{'ID'}, cant begin_work", $dbgerror . $curfunc);
            _updateField($dbh, 'class', "status='$keyvalue', ipteacher=?", 'where id=?', $classid, $remoteIp);
          }


        }else{
          my $keyfm = getField('keys', 'value', 'where key=?', "FM_$classid");
                         if($keyfm eq undef){ $keyfm = ' '; }
          $cmd_action = 'disableclass';
          $keyvalue = '[[class_status_suspend]]';

          $dbh->begin_work or writeMsg("Error:$hashField{'ID'}, cant begin_work", $dbgerror . $curfunc);
          if($classpermision =~ m/[[class_permision_YI]]/ ){
            eval{
              _modifyFieldData($dbh, 'keys', 'value', 'where key=?', 'ClassList', 'deleteClass', $classid);
              _deleteRecord($dbh, 'keys', 'where key=?', "Class_$classid");
              _deleteRecord($dbh, 'keys', 'where key=?', "FM_$classid");
              _deleteRecord($dbh, 'keys', 'where key=?', "OkAuth_$classid");
              _deleteRecord($dbh, 'keys', 'where key=?', "NoAuth_$classid");
              _updateField($dbh, 'class', 'sitefm=?', 'where id=?', $classid, $keyfm);
              _updateField($dbh, 'class', "status='$keyvalue', ipteacher=?", 'where id=?', $classid, $remoteIp);
            };

          }else{
#           ------ Only Allow login and Shares resouces -------
            _updateField($dbh, 'class', "status='$keyvalue', ipteacher=?", 'where id=?', $classid, $remoteIp);
          }

        }





        if($@){
          $dbh->rollback or writeMsg("cant rollback".$dbh->errstr, $dbgerror . $curfunc);
          writeMsg("rollback because error in eval; ".$@.$dbh->errstr, $dbginfo . $curfunc);
        }else{
          if(! $dbh->commit){
            writeMsg("error commit".$@.$dbh->errstr, $dbgerror . $curfunc);
          }else{
                  checkExec($curfunc, "su1 cms_command $cmd_action $classid $rooms $listusr4share");  ### SambaControlClasss
            checkExec($curfunc, "su1 HUP_squid_redirect");
          }
        }

      }else{
        writeMsg("error richt default on keyfield :$keyfield:", $dbgerror . $curfunc);
      }

    }elsif($hashField{'TY'} =~ /_SELECT/){
#     ===== write the new value for the permanet classroom
#      updateField('class', "$simulfield=?", 'where id=?', $classid, $keyvalue);


###########################################################################################################
######### Modif for doing an update on table keys, when the teacher changes the permanent classroom #######
## this only can be made if the class is disable, so there is no need to modify keys, so there is a lot of code that can be cancel!!!

                        my $dbh = getDbConnect(1,1);
                        my $teacherid = _getUsrConnectInfo($dbh, 'usrid');
                        my $remoteIp;
                        if(%ENV->{'HTTP_X_FORWARDED_FOR'}){
                                $remoteIp= %ENV->{'HTTP_X_FORWARDED_FOR'};
                        }else{
                                $remoteIp= %ENV->{'REMOTE_ADDR'};
                        }
                my $curaula  = _getField($dbh, 'classlayout', 'id', 'where pcip=?', $remoteIp);                                 ###030203

                        my $classpersis;
                        $dbh->begin_work or writeMsg("Error:$hashField{'TY'}, cant begin_work", $dbgerror . $curfunc);
                        if(!$keyvalue){ 
                                ### change the permanent class to no one, so no more free logins for students ###
                                $classpersis = '_BLANK_';
                        }else{
                                ### change the permanent class to another one ###
                                $classpersis = $keyvalue;
                        }

                        eval{
                                _updateField($dbh, 'class', "$simulfield=?", 'where id=?', $classid, $keyvalue);
#                               _modifyFieldData($dbh, 'keys','value','where key=?',"ClassList",'updateClassAula',"$classid:_BLANK_:_BLANK_:$curaula:$classpersis") or die;  

                        };



                        if($@){
                                $dbh->rollback or writeMsg("cant rollback".$dbh->errstr, $dbgerror . $curfunc);
                                writeMsg("rollback because error in eval; ".$@.$dbh->errstr, $dbginfo . $curfunc);
                        }else{
                                if(! $dbh->commit){
                                        writeMsg("error commit".$@.$dbh->errstr, $dbgerror . $curfunc);
                                }else{
                                        checkExec($curfunc, "su1 HUP_squid_redirect");
                                }
                        }

######### End of  permanent classroom ############################################################


    }else{
      writeMsg("error richt default on keyfield :$keyfield:", $dbgerror . $curfunc);
    }

  } #=== End Process POST ===


# ============================================== Process Request GET ====================== 
  my $dbh = getDbConnect(1,1);

# =========== Get Class Status - active suspend ===================
  my $strSQL    = 'select status, permision from class where id=?';
  my $sth = $dbh->prepare($strSQL);
  $sth->execute($classid);
  my ($status, $permision)  = $sth->fetchrow_array;

  my $teacherpermision = _getUsrConnectInfo($dbh, 'permision');   ### added 030203


  $strSQL = "select distinct id from classlayout";
  my $classroom_ref = $dbh->selectall_arrayref($strSQL);

  $strSQL = "select $simulfield from class where id=?";
  $sth = $dbh->prepare($strSQL);
  $sth->execute($classid);
  my ($simulvalue)  = $sth->fetchrow_array;

  my $curvalue   = '';
  my $curlabel = '[[class_status_active_IT]]';
  my $onclick    = '';
  my $check      = '';
  my $nameaction = '';

  my %hashDescription = (
       tableTitle => "[[FM_controlclass_tableTitle_IT]] $classid",
       alertfm    => '[[FM_controlclass_alertfm_IT]]',
       class      => '[[FM_controlclass_status_IT]]',
       share      => '[[FM_controlclass_share_IT]]',
       web        => '[[FM_controlclass_web_IT]]',
       fm         => '[[FM_controlclass_fm_IT]]',
       simulimp   => '[[FM_controlclass_simulimp_IT]]',
     );


  my %hashChecks = (
       class =>{
                id          => 'class',
                dbfield     => 'status',
                value       => "$status",
                value4check => '[[class_status_active]]',
                label       => "$curlabel",
                type        => 'checkbox',
                behaviour   => 'assign',
       },
       share =>{
                id          => 'share',
                dbfield     => 'permision',
                value       => "$permision",
                value4check => '[[usr_permision_SH]]',
                label       => "$curlabel",
                type        => 'checkbox',
                behaviour   => 'match',
       },
       web =>{
                id          => 'web',
                dbfield     => 'permision',
                value       => "$permision",
                value4check => '[[usr_permision_WW]]',
                label       => "$curlabel",
                type        => 'checkbox',
                behaviour   => 'match',
       },
       fm =>{
                id          => 'fm',
                dbfield     => 'permision',
                value       => "$permision",
                value4check => 'fm',
                label       => "$curlabel",
                type        => 'checkbox',
                behaviour   => 'match',
       },
     );

</%init>