Location: PHPKode > projects > Blandware AtLeap Lite - CMS on PHP > atleaplite/include/actions/message.php
<?php
/*
 *  Copyright 2008 Blandware (http://www.blandware.com)
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

/**
 * Actions for messages.
 *
 * @package     AtleapLite
 * @author      Roman Puchkovskiy
 * @license     http://www.apache.org/licenses/LICENSE-2.0  Apache License, Version 2.0
 */

/**
 * Lists message bundles.
 */
function listMessageBundles() {
    global $smarty;

    $languages =& getLanguages();
    $pager = getPager(array('totalItems' => count($languages)));
    exportPagerData($pager, $smarty, $languages);

    $smarty->assign('template', 'message_bundle/list.tpl');
    $smarty->assign('title', getMessage('messageBundle.list.title'));

    $smarty->assign('allowedUpdateMessageBundle', allowed('updateMessageBundle'));

    setSystemMenuItemBold('listMessageBundles');
    $smarty->assign('dontNeedMdelButton', true);
}

/**
 * Updates messages.
 *
 * @param object $form  form object
 * @param string $code  language code
 */
function doUpdateMessages(&$form, $code)
{
    $bundle = $form->getElementValue('resources');

    saveMessageBundle($bundle, $code);
}

/**
 * Creates a messages form.
 *
 * @param string $method    HTTP method
 * @param bool $init        whether form needs to be initialized from dao
 * @param string $code      code of language for which to edit message bundle
 * @return object created form
 */
function &createMessagesForm($method, $init, $code) {
    $params = array();
    $params['code'] = $code;

    $form = new FormBase('updateMessageBundle', $method, buildUrl('updateMessageBundle', $params));

    $languages =& getLanguages();
    $bundles = loadMessageBundlesAsText();
    $language = $languages[$code];
    $form->addTextareaElement('resources', getMessage('language.' . $language->code), array('rows' => 20, 'cols' => 60));
    if ($init) {
        $elem =& $form->getElement('resources');
        $elem->setValue($bundles[$language->code]);
    }

    $form->addProceedElement(getMessage('common.button.update'));
    $form->addCancelElement(getMessage('common.button.cancel'));
    
    return $form;
}

/**
 * Shows a page with form to update message bundle.
 */
function callUpdateMessageBundle()
{
    global $smarty, $bottomLinks;

    setSystemMenuItemBold('listMessageBundles');

    loadMessageBundles(true);

    $form =& createMessagesForm('POST', true, $_GET['code']);

    showForm($smarty, $form, 'message_bundle/update.tpl', getMessage('messageBundle.update.title'));
}

/**
 * Updates message bundle.
 */
function updateMessageBundle()
{
    global $smarty, $bottomLinks;

    if (isCancelled()) {
        redirect(getMessagesFormUrl());
    }

    setSystemMenuItemBold('updateMessages');

    $form =& createMessagesForm('POST', false, $_GET['code']);

    if ($form->validate()) {
        doUpdateMessages($form, $_GET['code']);
        redirect(getMessagesFormUrl());
    } else {
        showForm($smarty, $form, 'message_bundle/update.tpl', getMessage('messageBundle.update.title'));
    }
}

/**
 * Returns URL to page with messages form.
 *
 * @return URL
 */
function getMessagesFormUrl() {
    return buildUrl('listMessageBundles');
}


?>
Return current item: Blandware AtLeap Lite - CMS on PHP