<?php

if (!defined('sugarEntry') || !sugarEntry)
    die('Not A Valid Entry Point');


//	require_once('modules/EcmGroupFkPackages/HeaderMenu.php');

/* * *******************************************************************************
 * SugarCRM is a customer relationship management program developed by
 * SugarCRM, Inc. Copyright (C) 2004 - 2007 SugarCRM Inc.
 *
 * This program is free software; you can redistribute it and/or modify it under
 * the terms of the GNU General Public License version 3 as published by the
 * Free Software Foundation with the addition of the following permission added
 * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
 * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
 * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
 * details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program; if not, see http://www.gnu.org/licenses or write to the Free
 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 * 02110-1301 USA.
 *
 * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
 * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
 *
 * The interactive user interfaces in modified source and object code versions
 * of this program must display Appropriate Legal Notices, as required under
 * Section 5 of the GNU General Public License version 3.
 *
 * In accordance with Section 7(b) of the GNU General Public License version 3,
 * these Appropriate Legal Notices must retain the display of the "Powered by
 * SugarCRM" logo. If the display of the logo is not reasonably feasible for
 * technical reasons, the Appropriate Legal Notices must display the words
 * "Powered by SugarCRM".
 * ****************************************************************************** */


global $sugar_version, $sugar_config, $current_user, $app_strings, $mod_strings;
global $app_list_strings;


require_once('modules/EcmGroupFkPackages/EcmGroupService.php');
require_once('modules/EcmTexts/EcmText.php');
require_once ('include/time.php');

global $theme;
$theme_path = "themes/" . $theme . "/";
$image_path = $theme_path . "images/";
require_once ($theme_path . 'layout_utils.php');

$xtpl = new XTemplate('modules/EcmGroupFkPackages/Settings.html');
$xtpl->assign("MOD", $mod_strings);
$xtpl->assign("APP", $app_strings);

if (isset($_REQUEST['return_module']))
    $xtpl->assign("RETURN_MODULE", $_REQUEST['return_module']);
if (isset($_REQUEST['return_action']))
    $xtpl->assign("RETURN_ACTION", $_REQUEST['return_action']);
if (isset($_REQUEST['return_id']))
    $xtpl->assign("RETURN_ID", $_REQUEST['return_id']);
if (empty($_REQUEST['return_id']))
    $xtpl->assign("RETURN_ACTION", 'index');

/*
  $json = getJSONobj();
  $scriptOpt = '<script language="javascript">
  var MOD = '.str_replace('&quot;','\"',$json->encode($mod_strings)).';
  </script>';
  echo $scriptOpt;
 */

$cc = EcmGroupFkPackage::loadSettings();

if (is_admin($current_user)) {

    $xtpl->assign("DEFAULT_PAYMENT_CONDITION_OPTIONS", get_select_options_with_id(EcmGroupFkPackage::getPositionList('ecmpaymentconditions', true), $cc['default_payment_condition']));
    $xtpl->assign("DEFAULT_DELIVERY_CONDITION_OPTIONS", get_select_options_with_id(EcmGroupFkPackage::getPositionList('ecmdeliveryconditions', true), $cc['default_delivery_condition']));
    $xtpl->assign("DEFAULT_DOCUMENT_TEMPLATE_OPTIONS", get_select_options_with_id(EcmGroupFkPackage::getPositionList('ecmdocumenttemplates'), $cc['default_document_template']));

    $roles = EcmGroupFkPackage::getPositionList('acl_roles');
    $xtpl->assign("DEFAULT_REPRESENTATIVE_ROLE_ID_OPTIONS", get_select_options_with_id($roles, $cc['default_representative_role_id']));
    $xtpl->assign("DEFAULT_REPRESENTATIVE_EXTRA_ROLE_ID_OPTIONS", get_select_options_with_id($roles, $cc['default_representative_extra_role_id']));
    $xtpl->assign("DEFAULT_MANAGER_ROLE_ID_OPTIONS", get_select_options_with_id($roles, $cc['default_manager_role_id']));

    $xtpl->assign("CREATING_INVOICE_DIRECT_FROM_QUOTE", ($cc['creating_invoice_direct_from_quote'] == 1 ? 'CHECKED' : ''));
    $xtpl->assign("CHECKBOX_DEMO", ($cc['checkbox_demo'] == 1 ? 'CHECKED' : ''));
    $xtpl->assign("CHECKBOX_SHOW_IMAGES_ON_OFFERS", ($cc['show_images_on_offers'] == 1 ? 'CHECKED' : ''));

    //added 23.12.2009 michal
    $xtpl->assign("ROWS_ON_ITEM_LIST_GLOBAL", $cc['rows_on_item_list_global']);
    $xtpl->assign("ROW_ITEM_HEIGHT_GLOBAL", $cc['row_item_height_global']);
    $xtpl->assign("ROW_ITEM_HEIGHT_SELECTED_GLOBAL", $cc['row_item_height_selected_global']);
    $xtpl->assign("QUICK_PRODUCT_ITEM_ADDING_GLOBAL", ($cc['quick_product_item_adding_global'] == 1 ? 'CHECKED' : ''));
    $xtpl->assign("SHOW_PDF_IN_DIV_GLOBAL", ($cc['show_pdf_in_div_global'] == 1 ? 'CHECKED' : ''));


    $xtpl->parse("main.admin_settings");
}

if ($cc['settings_user_save'])
    $xtpl->assign("ROWS_ON_ITEM_LIST", $cc['rows_on_item_list']);
else
    $xtpl->assign("ROWS_ON_ITEM_LIST", $cc['rows_on_item_list_global']);

if ($cc['settings_user_save'])
    $xtpl->assign("ROW_ITEM_HEIGHT", $cc['row_item_height']);
else
    $xtpl->assign("ROW_ITEM_HEIGHT", $cc['row_item_height_global']);

if ($cc['settings_user_save'])
    $xtpl->assign("ROW_ITEM_HEIGHT_SELECTED", $cc['row_item_height_selected']);
else
    $xtpl->assign("ROW_ITEM_HEIGHT_SELECTED", $cc['row_item_height_selected_global']);

if ($cc['settings_user_save'])
    $xtpl->assign("QUICK_PRODUCT_ITEM_ADDING", ($cc['quick_product_item_adding'] == 1 ? 'CHECKED' : ''));
else
    $xtpl->assign("QUICK_PRODUCT_ITEM_ADDING", ($cc['quick_product_item_adding_global'] == 1 ? 'CHECKED' : ''));
//added 23.12.2009 michal
if ($cc['settings_user_save'])
    $xtpl->assign("SHOW_PDF_IN_DIV", ($cc['show_pdf_in_div'] == 1 ? 'CHECKED' : ''));
else
    $xtpl->assign("SHOW_PDF_IN_DIV", ($cc['show_pdf_in_div_global'] == 1 ? 'CHECKED' : ''));

$xtpl->parse("main.my_own_settings");

echo "\n<p>\n";
echo get_module_title('EcmGroupFkPackages', $GLOBALS['mod_strings']['LBL_SETTINGS_TITLE'], true);
echo "\n</p>\n";
$tabs = "";
$tabs.='<ul class="subpanelTablist" style="margin-top:10px;" id="groupTabsPanels">';
if (is_admin($current_user)) {
    $tabs.='<li class="active" id="l_admin">
<a class="current" id="a_admin" href="javascript:showTab(\'admin\');">' . $mod_strings['LBL_ADMIN_SETTINGS'] . '</a>
</li>
<li class="" id="l_global">
<a class="other" id="a_global" href="javascript:showTab(\'global\');">' . $mod_strings['LBL_GLOBAL_SETTINGS'] . '</a>
</li>';

    $tabs.='<li class="" id="l_user">
<a class="other" id="a_user" href="javascript:showTab(\'user\');">' . $mod_strings['LBL_MY_OWN_SETTINGS'] . '</a>
</li>
</ul>';
} else {
    $tabs.='<li class="active" id="l_user">
<a class="current" id="a_user" href="javascript:showTab(\'user\');">' . $mod_strings['LBL_MY_OWN_SETTINGS'] . '</a>
</li>';
}
$tabs.='</ul>';
$xtpl->assign("TABS", $tabs);

$xtpl->parse("main");
$xtpl->out("main");

require_once('include/javascript/javascript.php');
$javascript = new javascript();
//   $javascript->setFormName('PDFLanguages');
//   $javascript->addAllFields('');
//BUILDER:START Pro only
//   $javascript->addFieldGeneric(              'team_name',          'varchar', $app_strings['LBL_TEAM'] ,'true');
//   $javascript->addToValidateBinaryDependency('team_name',          'alpha',   $app_strings['ERR_SQS_NO_MATCH_FIELD'] . $app_strings['LBL_TEAM'],        'false', '', 'team_id');
//BUILDER:END Pro only
//   $javascript->addFieldGeneric('central_areacode', 'varchar', $mod_strings['LBL_CENTRAL_AREACODE'] , 'true');
//   $javascript->addToValidateBinaryDependency('central_areacode', 'alpha' ,$app_strings['ERR_SQS_NO_MATCH_FIELD'].$mod_strings['LBL_CENTRAL_AREACODE'], 'false', '', 'team_id');
//   $javascript->addToValidateBinaryDependency('assigned_user_name', 'alpha',   $app_strings['ERR_SQS_NO_MATCH_FIELD'] . $app_strings['LBL_ASSIGNED_TO'], 'false', '', 'assigned_user_id');

echo $javascript->getScript();
?>