<?php
/**
 * The configure xuanxuan view file of setting module of XXB.
 *
 * @copyright   Copyright 2009-2023 禅道软件（青岛）有限公司(ZenTao Software (Qingdao) Co., Ltd., www.zentao.net)
 * @license     ZOSL (https://zpl.pub/page/zoslv1.html)
 * @author      Gang Liu <liugang@cnezsoft.com>
 * @package     setting
 * @version     $Id$
 * @link        https://xuanim.com
 */
?>
<?php include '../../../common/view/header.html.php';?>
<?php $this->app->loadLang('client')?>
<div class='panel'>
  <div class='panel-heading'>
    <strong><?php echo $lang->setting->param;?></strong>
  </div>
  <form method='post' id='ajaxForm' class='form-ajax'>
    <table class='table table-form'>
      <tbody>
        <tr>
          <th class='w-150px'><?php echo $lang->im->version;?></th>
          <td class='w-300px'><?php echo $config->xuanxuan->global->version;?></td>
          <td></td>
        </tr>
        <tr>
          <th><?php echo $lang->im->key;?></th>
          <td class='code'>
            <?php $key   = zget($config->xuanxuan, 'key', '');?>
            <?php $style = (!$key or $key == str_repeat(8, 32)) ? "style='margin-bottom: 0px; border-color: rgb(149, 59, 57);'" : '';?>
            <?php echo $type == 'edit' ? html::input('key', zget($config->xuanxuan, 'key', ''), "class='form-control' readonly='readonly' $style") : zget($config->xuanxuan, 'key', '');?>
            <?php if($type == 'edit' && (!$key or $key == str_repeat(8, 32))):?>
            <span id="keyLabel" for="key" class="text-error red"><?php echo !$key ? $lang->im->errorKey : $lang->im->defaultKey;?></span>
            <?php endif;?>
          </td>
          <td><?php echo $type == 'edit' ? html::a('javascript:void(0)', $lang->im->createKey, 'onclick="createKey()"') : '';?></td>
        </tr>
        <tr>
          <th><?php echo $lang->im->backendLang;?></th>
          <td><?php echo $type == 'edit' ? html::select('backendLang', $config->langs, $config->xuanxuan->backendLang, "class='form-control'") : zget($config->langs, $config->xuanxuan->backendLang, '');?></td>
          <td></td>
        </tr>
        <tr>
          <th><?php echo $lang->im->xxdServer;?></th>
          <td><?php echo $type == 'edit' ? html::input('server', $server, "class='form-control'") : $server;?></td>
          <td class='text-muted'><?php if($type == 'edit') echo $lang->im->xxdServerTip;?></td>
        </tr>
        <tr>
          <th><?php echo $lang->im->iceServers;?></th>
          <td><?php echo $type == 'edit' ? html::textarea('iceServers', str_replace(',', "\n", zget($config->xuanxuan, 'iceServers', '')), "class='form-control'")  : str_replace(',', "\n", zget($config->xuanxuan, 'iceServers', ''));?></td>
          <td class='text-muted'><?php if($type == 'edit') echo $lang->im->iceServersTip; ?></td>
        </tr>
        <tr>
          <th><?php echo $lang->im->pollingInterval;?></th>
          <td><?php echo $type == 'edit' ? html::input('pollingInterval', zget($config->xuanxuan, 'pollingInterval', 15), " class='form-control'") : zget($config->xuanxuan, 'pollingInterval', 60) . $lang->im->secs;?></td>
          <td class='text-muted'><?php if($type == 'edit') echo $lang->im->xxdPollIntTip;?></td>
        </tr>
        <tr>
          <th><?php echo $lang->im->xxd->ip;?></th>
          <td class='code'><?php echo $type == 'edit' ? html::input('ip', zget($config->xuanxuan, 'ip', '0.0.0.0'), "class='form-control' placeholder='{$lang->im->placeholder->xxd->ip}'") : zget($config->xuanxuan, 'ip', '0.0.0.0');?></td>
          <td></td>
        </tr>
        <tr>
          <th><?php echo $lang->im->xxd->chatPort;?></th>
          <td><?php echo $type == 'edit' ? html::input('chatPort', zget($config->xuanxuan, 'chatPort', 11444), "placeholder='{$lang->im->placeholder->xxd->chatPort}' class='form-control'") : zget($config->xuanxuan, 'chatPort', 11444);?></td>
          <td></td>
        </tr>
        <tr>
          <th><?php echo $lang->im->xxd->commonPort;?></th>
          <td><?php echo $type == 'edit' ? html::input('commonPort', zget($config->xuanxuan, 'commonPort', 11443), "placeholder='{$lang->im->placeholder->xxd->commonPort}' class='form-control'") : zget($config->xuanxuan, 'commonPort', 11443);?></td>
          <td></td>
        </tr>
        <tr>
          <th><?php echo $lang->im->xxd->uploadFileSize;?></th>
          <td>
            <?php if($type == 'edit'):?>
            <div class='input-group'>
              <span class='input-group-addon'><?php echo $lang->im->xxd->max;?></span>
              <?php echo html::input('uploadFileSize', zget($config->xuanxuan, 'uploadFileSize', 20), "class='form-control' placeholder='{$lang->im->placeholder->xxd->uploadFileSize}' ");?>
              <span class='input-group-addon'>M</span>
            </div>
            <?php else:?>
            <?php echo $lang->im->xxd->max . zget($config->xuanxuan, 'uploadFileSize', 20) . 'M';?>
            <?php endif;?>
          </td>
          <td></td>
        </tr>
        <?php if(commonModel::isLicensedMethod('im', 'fileEncrypt')):?>
        <tr>
          <th><?php echo $lang->im->xxd->fileEncryption;?></th>
          <td>
            <?php $fileEncrypt = zget($config->xuanxuan, 'fileEncrypt', 'off');?>
            <?php echo ($type == 'edit' && $fileEncrypt == 'off') ? html::radio('fileEncrypt', $lang->im->fileEncryptOptions, 'off', "class='checkbox'") : zget($lang->im->fileEncryptOptions, $fileEncrypt);?>
          </td>
          <td class='text-muted'><?php if($type == 'edit') echo $lang->im->xxdFileEncryptTip;?></td>
        </tr>
        <?php endif;?>
        <?php if(commonModel::isLicensedMethod('im', 'messageEncrypt')):?>
        <tr>
          <th><?php echo $lang->im->xxd->messageEncryption;?></th>
          <td>
            <?php $messageEncrypt = zget($config->xuanxuan, 'messageEncrypt', 'off');?>
            <?php echo ($type == 'edit' && $messageEncrypt == 'off') ? html::radio('messageEncrypt', $lang->im->messageEncryptOptions, 'off', "class='checkbox'") : zget($lang->im->messageEncryptOptions, $messageEncrypt);?>
          </td>
          <td class='text-muted'><?php if($type == 'edit') echo $lang->im->xxdMessageEncryptTip;?></td>
        </tr>
        <?php endif;?>
        <tr>
          <th><?php echo $lang->im->tokenLifetime;?></th>
          <td>
            <?php if($type == 'edit'):?>
            <div class='input-group'>
              <?php echo html::input('tokenLifetime', zget($config->xuanxuan, 'tokenLifetime', 30), "class='form-control' ");?>
              <span class='input-group-addon'><?php echo $lang->date->day;?></span>
            </div>
            <?php else:?>
            <?php echo zget($config->xuanxuan, 'tokenLifetime', 30) . $lang->date->day;?>
            <?php endif;?>
          </td>
          <td></td>
        </tr>
        <tr>
          <th><?php echo $lang->im->tokenAuthWindow;?></th>
          <td>
            <?php if($type == 'edit'):?>
            <div class='input-group'>
              <?php echo html::input('tokenAuthWindow', zget($config->xuanxuan, 'tokenAuthWindow', 20), "class='form-control' ");?>
              <span class='input-group-addon'><?php echo $lang->im->secs;?></span>
            </div>
            <?php else:?>
            <?php echo zget($config->xuanxuan, 'tokenAuthWindow', 20) . $lang->im->secs;?>
            <?php endif;?>
          </td>
          <td></td>
        </tr>
        <tr>
          <th><?php echo $lang->im->xxd->aes;?></th>
          <td>
            <?php $aes = zget($config->xuanxuan, 'aes', 'on');?>
            <?php echo $type == 'edit' ? html::radio('aes', $lang->im->aesOptions, $aes, "class='checkbox'") : zget($lang->im->aesOptions, $aes);?>
          </td>
          <td class='text-muted'><?php if($type == 'edit') echo $lang->im->xxdAESTip;?></td>
        </tr>
        <tr>
          <th><?php echo $lang->im->xxd->https;?></th>
          <td>
            <?php $https = zget($config->xuanxuan, 'https', 'off');?>
            <?php echo $type == 'edit' ? html::radio('https', $lang->im->httpsOptions, $https, "class='checkbox'") : zget($lang->im->httpsOptions, $https);?>
          </td>
          <td></td>
        </tr>
        <tr class='sslTR <?php if($https == 'off' || empty($type)) echo 'hide';?>'>
          <th><?php echo $lang->im->xxd->sslcrt;?></th>
          <td><?php echo html::textarea('sslcrt',  zget($config->xuanxuan, 'sslcrt', ''), "placeholder='{$lang->im->placeholder->xxd->sslcrt}' class='form-control'");?></td>
          <td></td>
        </tr>
        <tr class='sslTR <?php if($https == 'off' || empty($type)) echo 'hide';?>'>
          <th><?php echo $lang->im->xxd->sslkey;?></th>
          <td><?php echo html::textarea('sslkey',  zget($config->xuanxuan, 'sslkey', ''), "placeholder='{$lang->im->placeholder->xxd->sslkey}' class='form-control'");?></td>
          <td></td>
        </tr>
        <tr>
          <th><?php echo $lang->im->mobileClient;?></th>
          <td>
            <?php $mobileClient = zget($config->xuanxuan, 'mobileClient', 'on');?>
            <?php echo $type == 'edit' ? html::radio('mobileClient', $lang->im->mobileOptions, $mobileClient) : zget($lang->im->mobileOptions, $mobileClient);?>
          </td>
          <td></td>
        </tr>
        <tr>
          <th><?php echo $lang->im->debug;?></th>
          <td>
            <?php $debug = zget($config->xuanxuan, 'debug', 0);?>
            <?php echo $type == 'edit' ? html::radio('debug', $lang->im->debugStatus, $debug) : zget($lang->im->debugStatus, $debug);?>
          </td>
          <td></td>
        </tr>
        <tr>
          <th><?php echo $lang->im->logLevel;?></th>
          <td>
            <?php $logLevel = zget($config->xuanxuan, 'logLevel', 1);?>
            <?php echo $type == 'edit' ? html::radio('logLevel', $lang->im->logLevelOptions, $logLevel) : zget($lang->im->logLevelOptions, $logLevel);?>
          </td>
          <td></td>
        </tr>
        <?php if($type != 'edit'):?>
        <tr>
          <th><?php echo $lang->im->xxd->os;?></th>
          <td><?php echo html::select('os', $lang->im->osList, zget($config->xuanxuan, $os), "class='form-control chosen'");?></td>
          <td></td>
        </tr>
        <?php endif;?>
        <tr>
          <th></th>
          <td colspan='2'>
            <?php if($type == 'edit'):?>
              <?php echo html::submitButton();?>
              <?php echo html::a(helper::createLink('setting', 'xuanxuan'), $lang->goback, 'class="btn"');?>
            <?php else:?>
              <button type='button' class='btn btn-primary' id='downloadXXDPackage'><?php echo $lang->im->downloadXXD;?></button>
              <?php echo html::a(helper::createLink('setting', 'downloadXXD', 'type=config'), $lang->im->downloadConfig, "class='btn btn-primary download' target='hiddenwin'");?>
              <?php if($debug) echo html::a(helper::createLink('im', 'debug', 'source=setting'), $lang->im->viewDebug, "class='btn btn-primary viewDebug' data-toggle='modal'");?>
              <?php echo html::a(helper::createLink('setting', 'xuanxuan', 'type=edit'), $lang->im->changeSetting, "class='btn'");?>
              <div id='infoBox' class='text-error'>
                <span><?php echo $lang->setting->downloadFile;?>,</span>
                <span><?php echo $lang->setting->downloadAddress;?><a href="https://xuanim.com/page/download.html" target="_blank">https://xuanim.com/page/download.html</a>。</span>
                <span><?php echo $lang->client->downloadErrorTip;?></span>
                <span class='info'><?php echo $path;?></span>
                <span><?php echo $lang->client->inCatalog;?></span>
              </div>
            <?php endif;?>
          </td>
        </tr>
      </tbody>
    </table>
  </form>
</div>
<?php if($type == 'edit'): ?>
<div class="panel">
  <div class='panel-heading'>
    <strong style="color: red;"><?php echo $lang->setting->deleteMmessages; ?></strong>
  </div>
  <form method='post'>
    <table class='table table-form'>
      <tbody>
        <tr>
          <th class="w-150px"><?php echo $lang->setting->deleteType; ?></th>
          <td><?php echo html::radio('clearType', $lang->setting->deleteOptions, $clearType, "class='checkbox'");?></td>
        </tr>
        <tr>
          <th></th>
          <td><?php echo $lang->setting->validationTitle; ?></td>
        </tr>
        <tr>
          <th></th>
          <td style="color: #0d8aee;"><?php echo sprintf($lang->setting->validation, $clearFileName); ?></td>
        </tr>
        <tr>
          <th></th>
          <td class='text-muted'><?php echo $lang->setting->validationTip;?></td>
        </tr>
        <tr>
          <th></th>
        </tr>
        <tr>
          <th></th>
          <td><?php echo html::submitButton($lang->delete, 'btn btn-danger');?></td>
        </tr>
      </tbody>
    </table>
  </form>
</div>
<?php endif;?>
<?php include '../../../common/view/footer.html.php';?>
