<process>
  <name>testMail</name>
  <isValid>y</isValid>
  <version>1.1</version>
  <isActive>y</isActive>
   <description>This process tests the mail agent for egroupware</description>
  <lastModif>28/10/2005 [10:34:59]</lastModif>
  <sharedCode><![CDATA[<?php
//***************************************************************************
//* copyleft Regis dot Leroy at glconseil dot com                           *
//* This program 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.                                             *
//***************************************************************************
?>  ]]></sharedCode>
  <configs>
    <config>
      <wf_config_name>display_please_wait_message</wf_config_name>
      <wf_config_value></wf_config_value>
      <wf_config_value_int>1</wf_config_value_int>
    </config>
    <config>
      <wf_config_name>use_automatic_parsing</wf_config_name>
      <wf_config_value></wf_config_value>
      <wf_config_value_int>1</wf_config_value_int>
    </config>
    <config>
      <wf_config_name>show_activity_title</wf_config_name>
      <wf_config_value></wf_config_value>
      <wf_config_value_int>1</wf_config_value_int>
    </config>
    <config>
      <wf_config_name>show_instance_name</wf_config_name>
      <wf_config_value></wf_config_value>
      <wf_config_value_int>1</wf_config_value_int>
    </config>
    <config>
      <wf_config_name>show_instance_owner</wf_config_name>
      <wf_config_value></wf_config_value>
      <wf_config_value_int>1</wf_config_value_int>
    </config>
    <config>
      <wf_config_name>show_multiple_submit_as_select</wf_config_name>
      <wf_config_value></wf_config_value>
      <wf_config_value_int>0</wf_config_value_int>
    </config>
    <config>
      <wf_config_name>show_activity_info_zone</wf_config_name>
      <wf_config_value></wf_config_value>
      <wf_config_value_int>1</wf_config_value_int>
    </config>
    <config>
      <wf_config_name>draw_roles</wf_config_name>
      <wf_config_value></wf_config_value>
      <wf_config_value_int>1</wf_config_value_int>
    </config>
    <config>
      <wf_config_name>mail_smtp_profile</wf_config_name>
      <wf_config_value>default</wf_config_value>
      <wf_config_value_int></wf_config_value_int>
    </config>
  </configs>
  <activities>
    <activity>
      <name>View the Message</name>
      <type>view</type>
      <description>This 'view' activity is there to give a nicer view in read-only mode on the message for all users of the process.
We use the mail agent on it to prevent the owner (author of the message) that someones has consulted his message.</description>
      <lastModif>02/09/2005 [04:04:04]</lastModif>
      <isInteractive>y</isInteractive>
      <isAutoRouted>n</isAutoRouted>
      <roles>
        <role readonly="true">Validator</role>
        <role readonly="true">MailUser</role>
      </roles>
      <agents>
        <agent>
           <agent_type>mail_smtp</agent_type>
           <agent_datas>
               <agent_data>
                   <name>wf_to</name>
                   <value>%owner%</value>
               </agent_data>
               <agent_data>
                   <name>wf_cc</name>
                   <value></value>
               </agent_data>
               <agent_data>
                   <name>wf_bcc</name>
                   <value></value>
               </agent_data>
               <agent_data>
                   <name>wf_from</name>
                   <value>no-reply@nowhere.com</value>
               </agent_data>
               <agent_data>
                   <name>wf_replyto</name>
                   <value></value>
               </agent_data>
               <agent_data>
                   <name>wf_subject</name>
                   <value>%user% has consulted your message</value>
               </agent_data>
               <agent_data>
                   <name>wf_message</name>
                   <value>%user% has consulted your message called %instance_name%.</value>
               </agent_data>
               <agent_data>
                   <name>wf_send_mode</name>
                   <value>2</value>
               </agent_data>
               <agent_data>
                   <name>wf_agent_type</name>
                   <value>mail_smtp</value>
               </agent_data>
           </agent_datas>
        </agent>
      </agents>
      <code><![CDATA[<?php

$property_vars = array(
    'MYDEST' => '',
    'MYBODY' => '',
    'REFUSAL' => '',
);

//--------------------------------------
//
// handling data on the form
//
//--------------------------------------

// init with the property
foreach ($property_vars as $prop => $value)
{
  $property_vars[$prop] = $instance->get($prop);
}

//--------------------------------------
//
// handling results from the form
//
//--------------------------------------

//--------------------------------------
//
// showing the form
//
//--------------------------------------

  foreach ($property_vars as $prop => $value) 
  {
    $template->set_var(array($prop => $property_vars[$prop]));
  }

  //we want to display the owner
  $this->display_owner = 1;

  //we want the history of the instance
  $this->display_history= true;

  // submit options we want
  $this->submit_array['__Cancel'] = lang('Close');


?>      ]]></code>      <template><![CDATA[<table width="100%">
 <tr class="th">
    <td colspan="2">this a message made by {wf_owner}</td>
 </tr>
 </tr>
 
 <tr class="row_on">
    <td> From:</td>
    <td>{wf_owner}</td>
  </tr>
 <tr class="row_on">
    <td> To:</td>
    <td>{MYDEST}</td>
  </tr>
 <tr class="row_off">
    <td> subject:</td>
    <td>{wf_instance_name}</td>
  </tr>
 <tr class="row_on">
    <td> body:</td>
    <td> <textarea readonly="readonly" name="MYBODY" cols="76" rows="5">{MYBODY}</textarea></td>
  </tr>
 <tr class="row_on">
    <td> in case of BaAad REFUSAL:</td>
    <td> {REFUSAL}</td>
  </tr>
</table>      ]]></template>    </activity>
    <activity>
      <name>end</name>
      <type>end</type>
      <description>default end activity</description>
      <lastModif>01/09/2005 [09:13:00]</lastModif>
      <isInteractive>n</isInteractive>
      <isAutoRouted>y</isAutoRouted>
      <roles>
      </roles>
      <agents>
      </agents>
      <code><![CDATA[<?php
?>      ]]></code>    </activity>
    <activity>
      <name>Acknowledge user it was good</name>
      <type>activity</type>
      <description>This automatic activity send an email to the user to prevent him his mail was sent</description>
      <lastModif>01/09/2005 [09:13:00]</lastModif>
      <isInteractive>n</isInteractive>
      <isAutoRouted>y</isAutoRouted>
      <roles>
      </roles>
      <agents>
        <agent>
           <agent_type>mail_smtp</agent_type>
           <agent_datas>
               <agent_data>
                   <name>wf_to</name>
                   <value>%owner%</value>
               </agent_data>
               <agent_data>
                   <name>wf_cc</name>
                   <value></value>
               </agent_data>
               <agent_data>
                   <name>wf_bcc</name>
                   <value></value>
               </agent_data>
               <agent_data>
                   <name>wf_from</name>
                   <value>%user%</value>
               </agent_data>
               <agent_data>
                   <name>wf_replyto</name>
                   <value></value>
               </agent_data>
               <agent_data>
                   <name>wf_subject</name>
                   <value>Your mail was sent</value>
               </agent_data>
               <agent_data>
                   <name>wf_message</name>
                   <value>your mail for %property_MYDEST% was sent by the validator.

%signature%</value>
               </agent_data>
               <agent_data>
                   <name>wf_send_mode</name>
                   <value>2</value>
               </agent_data>
               <agent_data>
                   <name>wf_agent_type</name>
                   <value>mail_smtp</value>
               </agent_data>
           </agent_datas>
        </agent>
      </agents>
      <code><![CDATA[<?php
?>      ]]></code>    </activity>
    <activity>
      <name>Acknowledge user it was bad</name>
      <type>activity</type>
      <description>Boo, the validator said the mail was bad, send an email to the owner, aka the user starting the process, to tell him it was bad</description>
      <lastModif>01/09/2005 [09:13:00]</lastModif>
      <isInteractive>n</isInteractive>
      <isAutoRouted>y</isAutoRouted>
      <roles>
      </roles>
      <agents>
        <agent>
           <agent_type>mail_smtp</agent_type>
           <agent_datas>
               <agent_data>
                   <name>wf_to</name>
                   <value>%owner%</value>
               </agent_data>
               <agent_data>
                   <name>wf_cc</name>
                   <value></value>
               </agent_data>
               <agent_data>
                   <name>wf_bcc</name>
                   <value></value>
               </agent_data>
               <agent_data>
                   <name>wf_from</name>
                   <value>%user%</value>
               </agent_data>
               <agent_data>
                   <name>wf_replyto</name>
                   <value>%user%</value>
               </agent_data>
               <agent_data>
                   <name>wf_subject</name>
                   <value>Your mail was not sent</value>
               </agent_data>
               <agent_data>
                   <name>wf_message</name>
                   <value>Your mail for %property_MYDEST% was NOT sent by the validator.
here is his explanation: %property_REFUSAL%

%signature%</value>
               </agent_data>
               <agent_data>
                   <name>wf_send_mode</name>
                   <value>3</value>
               </agent_data>
               <agent_data>
                   <name>wf_agent_type</name>
                   <value>mail_smtp</value>
               </agent_data>
           </agent_datas>
        </agent>
      </agents>
      <code><![CDATA[<?php
?>      ]]></code>    </activity>
    <activity>
      <name>Send the message</name>
      <type>activity</type>
      <description>This automatic activity will send the message that the user was asking for.</description>
      <lastModif>28/10/2005 [10:21:20]</lastModif>
      <isInteractive>n</isInteractive>
      <isAutoRouted>y</isAutoRouted>
      <roles>
      </roles>
      <agents>
        <agent>
           <agent_type>mail_smtp</agent_type>
           <agent_datas>
               <agent_data>
                   <name>wf_to</name>
                   <value>%property_MYDEST%</value>
               </agent_data>
               <agent_data>
                   <name>wf_cc</name>
                   <value></value>
               </agent_data>
               <agent_data>
                   <name>wf_bcc</name>
                   <value></value>
               </agent_data>
               <agent_data>
                   <name>wf_from</name>
                   <value>%owner%</value>
               </agent_data>
               <agent_data>
                   <name>wf_replyto</name>
                   <value>%owner%</value>
               </agent_data>
               <agent_data>
                   <name>wf_subject</name>
                   <value>%instance_name%</value>
               </agent_data>
               <agent_data>
                   <name>wf_message</name>
                   <value>%property_MYBODY%</value>
               </agent_data>
               <agent_data>
                   <name>wf_send_mode</name>
                   <value>2</value>
               </agent_data>
               <agent_data>
                   <name>wf_agent_type</name>
                   <value>mail_smtp</value>
               </agent_data>
           </agent_datas>
        </agent>
      </agents>
      <code><![CDATA[<?php
?>      ]]></code>    </activity>
    <activity>
      <name>Validation</name>
      <type>switch</type>
      <description>The Validator validate the mail and send it by completing the activity. He can as well invalidate the mail.</description>
      <lastModif>02/09/2005 [03:06:38]</lastModif>
      <isInteractive>y</isInteractive>
      <isAutoRouted>y</isAutoRouted>
      <roles>
        <role>Validator</role>
        <role readonly="true">MailUser</role>
      </roles>
      <agents>
      </agents>
      <code><![CDATA[<?php
//avoid empty property warning
$instance->set('REFUSAL','');

$property_vars = array(
    'MYDEST' => '',
    'MYBODY' => '',
    'REFUSAL' => '',
);

//--------------------------------------
//
// handling data on the form
//
//--------------------------------------

// init variables with POST and if POST is empty 
// init with the property
foreach ($property_vars as $prop => $value)
{
  $property_vars[$prop] = get_var($prop,'any',$instance->get($prop));
}
//user commands   ****************
$ActBad = get_var('ActBad','POST',false);
$ActGood = get_var('ActGood','POST',false);
$ActLater = get_var('ActLater','POST',false);

//--------------------------------------
//
// handling results from the form
//
//--------------------------------------
$message = Array();
$checkforstaying = true;
if (($ActBad) || ($ActGood) || ($ActLater)) 
{
  // saving properties
  // if they changed
  foreach ($property_vars as $prop => $value)
  {
     if ($value != ($instance->get($prop)) ) 
     {
       $instance->set($prop,$value);
     }
  }
  if ($ActGood)
  {
     $checkforstaying = false;
     // going to next stage
     $instance->setNextActivity('Send the message');
     //complete and send the message
     $instance->complete();
  }
  if ($ActBad)
  {
    if($property_vars['REFUSAL']=='')
    {
      $message[]='You need to complete the REFUSAL to give some explanation of why it is baAad';
    }
    else
    {
       $checkforstaying = false;
       // going to next stage
       $instance->setNextActivity('Acknowledge user it was bad');
       //complete and sen the message
       $instance->complete();
    }
  }
  elseif($ActLater)
  {
    $checkforstaying = false;
    //leave without complete()
    $GLOBALS['workflow']['__leave_activity']=true;
  } 
} 

//now if we do not leave...
if ($checkforstaying)
{
//--------------------------------------
//
// showing the form
//
//--------------------------------------

  foreach ($property_vars as $prop => $value) 
  {
    $template->set_var(array($prop => htmlentities($property_vars[$prop])));
  }
  //some more form vars
  $template->set_var(array(
    'message' => implode('<br />',$message),
    )
  );

  //we want to display the owner
  $this->display_owner = 1;

  // submit options we want
  $this->submit_array['ActBad'] = array(label => 'BaAad', confirm => 'Are you sure you want to reject it?');
  $this->submit_array['ActGood'] = array(label => 'GoOod', confirm => 'this will send the email, you really want it, really?');
  $this->submit_array['ActLater'] = 'Later, I need more reflexion';

  //priority array
  $this->priority_array = array( 
        1 => lang('1 - low'),
        2 => lang('2 - normal'),
        3 => lang('3 - better'),
        4 => lang('4 - urgent'),
 );
}
?>      ]]></code>      <template><![CDATA[<table width="100%">
 <tr class="th">
    <td colspan="2">Decide if this message is goOod or baAad. If you choose goOod he will be sent, else he wont, and {wf_owner} will be warned of your choice by email</td>
 </tr>
 </tr>
 <tr class="row_off">
    <td>&nbsp;</td>
    <td>&nbsp;{message}</td>
  </tr>
 <tr class="row_on">
    <td> From:</td>
    <td>{wf_owner}</td>
  </tr>
 <tr class="row_on">
    <td> To:</td>
    <td>{MYDEST}</td>
  </tr>
 <tr class="row_off">
    <td> subject:</td>
    <td>{wf_instance_name}</td>
  </tr>
 <tr class="row_on">
    <td> body:</td>
    <td> <textarea readonly="readonly" name="MYBODY" cols="76" rows="5">{MYBODY}</textarea></td>
  </tr>
 <tr class="row_on">
    <td> in case of BaAad REFUSAL:</td>
    <td> <input type="text" name="REFUSAL" value="{REFUSAL}" /></td>
  </tr>
</table>      ]]></template>    </activity>
    <activity>
      <name>Send Automatic Mail to Validator</name>
      <type>activity</type>
      <description>This automatic activity sends an email to people in validator role. This email contains a lot of tips for writing emails with this agent</description>
      <lastModif>01/09/2005 [09:13:00]</lastModif>
      <isInteractive>n</isInteractive>
      <isAutoRouted>y</isAutoRouted>
      <roles>
        <role>Validator</role>
      </roles>
      <agents>
        <agent>
           <agent_type>mail_smtp</agent_type>
           <agent_datas>
               <agent_data>
                   <name>wf_to</name>
                   <value>%roles%</value>
               </agent_data>
               <agent_data>
                   <name>wf_cc</name>
                   <value></value>
               </agent_data>
               <agent_data>
                   <name>wf_bcc</name>
                   <value></value>
               </agent_data>
               <agent_data>
                   <name>wf_from</name>
                   <value>%user%</value>
               </agent_data>
               <agent_data>
                   <name>wf_replyto</name>
                   <value>%user%</value>
               </agent_data>
               <agent_data>
                   <name>wf_subject</name>
                   <value>A mail needs your validation</value>
               </agent_data>
               <agent_data>
                   <name>wf_message</name>
                   <value>%owner% wanted to send an email to %property_MYDEST%.
You need to check the message, the task is avaible %link_userinstance|here on the activity list%.
and just to test links I think you should try to click on this %link_http://www.egroupware.org/|egroupware.org external site link%. or on this %link_/index.php?menuaction=workflow.ui_useractivities.form|local installation link%.
And some other usefull links are:
%link_viewinstance|the instance in default view mode%.
%link_viewniceinstance|the instance in view activity%.
%link_admininstance|the instance in admin mode%.

We could as well use some defined tokens:
instance name and id: %instance_name% (%instance_id%)
activity name and id: %activity_name% (%activity_id%)
process name, version and id: %process_name% v%process_version% (%process_id%)

Last tip, if you want the \% character use the '\' charater to escape him.

=====================================
%signature%</value>
               </agent_data>
               <agent_data>
                   <name>wf_send_mode</name>
                   <value>3</value>
               </agent_data>
               <agent_data>
                   <name>wf_agent_type</name>
                   <value>mail_smtp</value>
               </agent_data>
           </agent_datas>
        </agent>
      </agents>
      <code><![CDATA[<?php
?>      ]]></code>    </activity>
    <activity>
      <name>Need to send an email</name>
      <type>start</type>
      <description>This start activity let the User write an email and send an email to the Validator Role, the user email is not sent. To test some other functionnalities we send an email to the user after he finished this activity to tell him we are sending an email to the validator</description>
      <lastModif>01/09/2005 [09:13:00]</lastModif>
      <isInteractive>y</isInteractive>
      <isAutoRouted>y</isAutoRouted>
      <roles>
        <role>MailUser</role>
      </roles>
      <agents>
        <agent>
           <agent_type>mail_smtp</agent_type>
           <agent_datas>
               <agent_data>
                   <name>wf_to</name>
                   <value>%user%</value>
               </agent_data>
               <agent_data>
                   <name>wf_cc</name>
                   <value></value>
               </agent_data>
               <agent_data>
                   <name>wf_bcc</name>
                   <value></value>
               </agent_data>
               <agent_data>
                   <name>wf_from</name>
                   <value>no-reply@nowhere.com</value>
               </agent_data>
               <agent_data>
                   <name>wf_replyto</name>
                   <value>%user%</value>
               </agent_data>
               <agent_data>
                   <name>wf_subject</name>
                   <value>Your message is waiting for validation</value>
               </agent_data>
               <agent_data>
                   <name>wf_message</name>
                   <value>Your message for %property_MYDEST% is actually awaiting for validation by the validator.

%signature%</value>
               </agent_data>
               <agent_data>
                   <name>wf_send_mode</name>
                   <value>0</value>
               </agent_data>
               <agent_data>
                   <name>wf_agent_type</name>
                   <value>mail_smtp</value>
               </agent_data>
           </agent_datas>
        </agent>
      </agents>
      <code><![CDATA[<?php
// retrieve submit options ****************
$ActSendtoValidation = get_var('ActSendtoValidation','POST',false);
//retrieve the message
$MYBODY =  get_var('MYBODY','POST','write your message here');
$MYDEST =  get_var('MYDEST','POST','');
//--------------------------------------
//
// handling results from the form
//
//--------------------------------------

$checkforcomplete = false;
$message = Array();

if ($ActSendtoValidation)
{
  //do some checks
  if (($MYBODY=='') || ($MYBODY=='write your message here') || ($MYBODY=='hey, you NEED to write your message here!'))
  {
    //no need to work with an empty message, even if the SendtoValidation is set
    $MYBODY = 'hey, you NEED to write your message here!';
    $message[] = 'you should write something in the message zone';
  }
  elseif ($MYDEST=='')
  {
    //no need to work with an empty dest, even if the SendtoValidation is set
    $message[] = 'write an email in the To: field, please';
  }
  elseif (get_var('wf_name','POST','')=='')
  {
    //empty subject for the message, baAad
    $message[] = 'write a subject for your message, please';
  }
  else
  {
    $checkforcomplete = true;
  }
}
if ($checkforcomplete)
{
  //save the instance property, we are in a start activity, 
  //which is a pseudo instance
  //this means we cannot keep track of instance properties when looping on the form
  //but it is not meaning you cannot write instance properties
  //in fact they are just in memory and written in database when the complete()
  //is done.
  $instance->set('MYDEST',$MYDEST);
  $instance->set('MYBODY',$MYBODY);

  // going to next stage
  $instance->complete();
  // the 'wf_name' and 'wf_priority' special properties are saved in
  // start_pos.php when completing
  //we use the name of the instance as the subject of the message
} 
else 
{

//--------------------------------------
//
// let's run_activity show the form
//
//--------------------------------------
   // submit options we want
   $this->submit_array['ActSendtoValidation'] = lang('Send to Validation');
   //Special cancel value
   $this->submit_array['__Cancel'] = lang('Cancel');
   //priority levels we want
   $this->priority_array = array( 
        1 => lang('1 - low'),
        2 => lang('2 - normal'),
        3 => lang('3 - hurry up'),
        4 => lang('4 - I need It!'),
        );
  //and default values and messages
  $template->set_var(array(
    'MYDEST' => $MYDEST,
    'MYBODY' => $MYBODY,
    'message' => implode('<br />',$message),
  ));
}

?>      ]]></code>      <template><![CDATA[<table width="100%">
 <tr class="th">
    <td colspan="2">this activity will begin a new test mail process, an instance will be created. Your message wont be sent. An email will be sent to the Validator and he will decide if your message can be sent or not. You will be warned of his decision.</td>
 </tr>
 <tr class="row_off">
    <td>&nbsp;</td>
    <td>&nbsp;{message}</td>
  </tr>
 <tr class="row_on">
    <td> To:</td>
    <td> <input type="text" name="MYDEST" value="{MYDEST}" /></td>
  </tr>
 <tr class="row_off">
    <td> enter the subject of your message:</td>
    <td> <input type="text" name="wf_name" value="" /></td>
  </tr>
 <tr class="row_on">
    <td> enter the body your message:</td>
    <td> <textarea name="MYBODY" cols="76" rows="5">{MYBODY}</textarea></td>
  </tr>
</table>      ]]></template>    </activity>
  </activities>
  <transitions>
     <transition>
       <from>Need to send an email</from>
       <to>Send Automatic Mail to Validator</to>
     </transition>
     <transition>
       <from>Send Automatic Mail to Validator</from>
       <to>Validation</to>
     </transition>
     <transition>
       <from>Validation</from>
       <to>Acknowledge user it was bad</to>
     </transition>
     <transition>
       <from>Validation</from>
       <to>Send the message</to>
     </transition>
     <transition>
       <from>Send the message</from>
       <to>Acknowledge user it was good</to>
     </transition>
     <transition>
       <from>Acknowledge user it was good</from>
       <to>end</to>
     </transition>
     <transition>
       <from>Acknowledge user it was bad</from>
       <to>end</to>
     </transition>
  </transitions>
</process>
