<?php
/**
 * File: $Id: s.xaradmin.php 1.28 03/02/08 17:38:40-05:00 John.Cox@mcnabb. $
 * 
 * Mail System
 * 
 * @package Xaraya eXtensible Management System
 * @copyright (C) 2003 by the Xaraya Development Team.
 * @license GPL {@link http://www.gnu.org/licenses/gpl.html} 
 * @link http://www.xaraya.com
 * @subpackage mail module
 * @author John Cox <admin@dinerminor.com> 
 */

/**
 * Update the configuration parameters of the module based on data from the modification form
 *
 * @author  John Cox <niceguyeddie@xaraya.com>
 * @access  public
 * @param   no parameters
 * @return  true on success or void on failure
 * @throws  no exceptions
 * @todo    nothing
*/
function mail_admin_modifyconfig()
{
    // Security Check
    if (!xarSecurityCheck('AdminMail')) return; 
    // Generate a one-time authorisation code for this operation
    $data['authid'] = xarSecGenAuthKey(); 
    // Quick Check for E_ALL
    $searchstrings = xarModGetVar('mail', 'searchstrings');
    $replacestrings = xarModGetVar('mail', 'replacestrings');
    if (empty($searchstrings)){
        $searchstrings = serialize('%%Search%%');
        xarModSetVar('mail', 'searchstrings', $searchstrings);
    }
    if (empty($replacestrings)){
        $replacestrings = serialize('Replace %%Search%% with this text');
        xarModSetVar('mail', 'replacestrings', $replacestrings);
    }
    $data['createlabel'] = xarML('Submit');
    $data['searchstrings'] = unserialize(xarModGetVar('mail', 'searchstrings'));
    $data['replacestrings'] = unserialize(xarModGetVar('mail', 'replacestrings'));

    // Get encoding
    $data['encoding'] = xarModGetVar('mail', 'encoding');

    // Include 'formcheck' JavaScript.
    // TODO: move this to a template widget when available.
    xarModAPIfunc(
        'base', 'javascript', 'modulefile',
        array('module'=>'base', 'filename'=>'formcheck.js')
    );

    if (xarModIsAvailable('scheduler')) {
        $data['intervals'] = xarModAPIFunc('scheduler','user','intervals');
        // see if we have a scheduler job running to send queued mail
        $job = xarModAPIFunc('scheduler','user','get',
                             array('module' => 'mail',
                                   'type' => 'scheduler',
                                   'func' => 'sendmail'));
        if (empty($job) || empty($job['interval'])) {
            $data['interval'] = '';
        } else {
            $data['interval'] = $job['interval'];
        }
        // get the waiting queue
        $serialqueue = xarModGetVar('mail','queue');
        if (!empty($serialqueue)) {
            $queue = unserialize($serialqueue);
        } else {
            $queue = array();
        }
        $data['unsent'] = count($queue);
    }

    // everything else happens in Template for now
    return $data;
} 
?>
