Condition checking 0.2 ;-)

to handle != conditions for the variable thats tested. 
For handling individual mixed things like: session:username:paul,!mary,fred
i have to squeeze my brain a little bit more.........

WARNING! This code is not tested, as of now it can contain errors.....


in the template file:

Session:

<roundcube:button command="print" imageSel="/images/buttons/print_sel.png" imageAct="/images/buttons/print_act.png" imagePas="/images/buttons/print_pas.png" width="32" height="32" title="printmessage" condition="session:username:test"/>
</div>

"is not"
<roundcube:button command="print" imageSel="/images/buttons/print_sel.png" imageAct="/images/buttons/print_act.png" imagePas="/images/buttons/print_pas.png" width="32" height="32" title="printmessage" condition="session:!username:test"/>
</div>

Array:
<roundcube:button command="print" imageSel="/images/buttons/print_sel.png" imageAct="/images/buttons/print_act.png" imagePas="/images/buttons/print_pas.png" width="32" height="32" title="printmessage" condition="session:username:test,peter,paul"/>
</div>


Variabe:

<roundcube:button command="print" imageSel="/images/buttons/print_sel.png" imageAct="/images/buttons/print_act.png" imagePas="/images/buttons/print_pas.png" width="32" height="32" title="printmessage" condition="var:day:monday"/>
</div>

"is not"
<roundcube:button command="print" imageSel="/images/buttons/print_sel.png" imageAct="/images/buttons/print_act.png" imagePas="/images/buttons/print_pas.png" width="32" height="32" title="printmessage" condition="var:!day:monday"/>
</div>

Array:
<roundcube:button command="print" imageSel="/images/buttons/print_sel.png" imageAct="/images/buttons/print_act.png" imagePas="/images/buttons/print_pas.png" width="32" height="32" title="printmessage" condition="var:day:monday,tuesday"/>
</div>


in main.inc:

function rcube_xml_command($command, $str_attrib, $add_attrib=array())
  {
  global $IMAP, $CONFIG, $OUTPUT;

 

  $command = strtolower($command);
  $attrib = parse_attrib_string($str_attrib) + $add_attrib;

 


   //check if tag is conditional
   if($attrib['condition']) {
    $condition=explode(':',$attrib['condition']);

   

   $logmesg="condition:".$condition[0].'='.print_array($condition);
//console($logmesg);

     if(strpos($condition[1],'!')) {
$condition[1]=substr($condition[1],1);
$cond_neg=1;
      }
    
    if(strpos($condition[2],',')) $condition_array=explode(',',$condition[2]);
    else $condition_array=array(0=>$condition[2]);

          

  switch ($condition[0]) {
  case 'session':
            if($cond_neg==1) {
   // if sesion var is set -> switch off command
       if(in_array($_SESSION[$condition[1]],$condition_array)) $command='none';
            }else{
             // if sesion var is not set -> switch off command
        if(!in_array($_SESSION[$condition[1]],$condition_array)) $command='none';
           }
  break;

   case 'var':

            

            if($cond_neg==1) {

    // if  var is  set -> switch off command
            if(in_array($$condition[1],$condition_array)) $command='none';
            }else{
                 // if sesion var is not set -> switch off command
            if(!in_array($$condition[1],$condition_array)) $command='none';
           }


break;


  default:
              if($cond_neg==1) {
  if($$condition[0]==$condition[1])) $command='none';
// condition is not handled -> switch off command
              }else{
                if(!$$condition[0]==$condition[1])) $command='none';
               }
  break;
  }
  }

Regards!

Edgar

Am 16.11.2006 um 13:58 schrieb Robin Elfrink:

Edgar Bueltemeyer wrote:


Its rather flexible and supports normal variables and Session-vars.....


I hadn't thought of that.


But how would you handle expressions like '!=' ?



Robin