<?php
/**
 * The manage privilege view of group module of ZDOO.
 *
 * @copyright   Copyright 2009-2018 青岛易软天创网络科技有限公司(QingDao Nature Easy Soft Network Technology Co,LTD, www.cnezsoft.com)
 * @license     ZPL (http://zpl.pub/page/zplv12.html)
 * @author      Xiying Guan <guanxiying@xirangit.com>
 * @package     group
 * @version     $Id: managepriv.html.php 4129 2013-01-18 01:58:14Z wwccss $
 * @link        http://www.zdoo.com
 */
?>
<?php include '../../common/view/header.html.php';?>
<div id='mainTitle' class='clearfix'>
  <div class='btn-toolbar pull-left'>
    <?php if(!isonlybody()):?>
    <?php echo html::a('javascript:history.go(-1);', '<i class="icon icon-back icon-sm"></i> ' . $lang->goback, "class='btn btn-back'");?>
    <div class="divider"></div>
    <?php endif;?>
    <div class="page-title">
      <span class="text"><?php echo substr($title, 0, strrpos($title, $lang->minus));?></span>
    </div>
  </div>
</div>
<form class='form panel' id='ajaxForm' method='post'>
  <div class='panel-body'>
    <?php if($type == 'byGroup'):?>
    <div class='row'>
      <div class='col-xs-6'>
        <div class='apps-container' id='unauthorized'>
          <div class='apps-heading'><strong><?php echo $lang->group->noPriv?></strong></div>
          <div class='apps-list row'>
            <?php foreach($rights as $code => $right):?>
            <?php if($right['right'] != 1):?>
            <div class='col col-xs-3'>
              <div class='app-item text-center'>
                <?php
                if($right['id'] == 'superadmin')
                {
                    echo "<div class='avatar avatar-app avatar-xl'><i class='icon icon-config-outline'></i></div>";
                }
                elseif($right['icon'])
                {
                    echo "<div class='avatar avatar-app avatar-xl' data-code='$code'>" . html::image($right['icon']) . "</div>";
                }
                else
                {
                    $name = $right['abbr'] ? $right['abbr'] : $right['name'];
                    $rightName = validater::checkCode(substr($name, 0, 1)) ? strtoupper(substr($name, 0, 1)) : substr($name, 0, 3);
                    if(validater::checkCode(substr($name, 0, 1)) and validater::checkCode(substr($name, 1, 1)))   $rightName .= strtoupper(substr($name, 1, 1));
                    if(validater::checkCode(substr($name, 0, 1)) and !validater::checkCode(substr($name, 1, 1)))  $rightName .= strtoupper(substr($name, 1, 3));
                    if(!validater::checkCode(substr($name, 0, 1)) and validater::checkCode(substr($name, 3, 1)))  $rightName .= strtoupper(substr($name, 3, 1));
                    if(!validater::checkCode(substr($name, 0, 1)) and !validater::checkCode(substr($name, 3, 1))) $rightName .= substr($name, 3, 3);
                    echo "<div class='avatar avatar-app avatar-xl' data-code='$code' data-id='{$right['id']}' data-name='$rightName'></div>";
                }
                ?>
                <div class='app-name text-ellipsis'><?php echo $right['name']; ?></div>
                <input class='hidden' type='checkbox' name='apps[]' value='<?php echo $code; ?>' />
              </div>
            </div>
            <?php endif?>
            <?php endforeach?>
          </div>
        </div>
      </div>
      <div class='col-xs-6'>
        <i class='icon icon-swap-h icon-md drag-direction-icon' title='<?php echo $lang->group->manageAppPrivTip; ?>'></i>
        <div class='apps-container' id='authorized'>
          <div class='apps-heading'><strong><?php echo $lang->group->havePriv?></strong></div>
          <div class='apps-list row'>
            <?php foreach($rights as $code => $right):?>
            <?php if($right['right'] == 1):?>
            <div class='col col-xs-3'>
              <div class='app-item text-center'>
                <?php
                if($right['id'] == 'superadmin')
                {
                    echo "<div class='avatar avatar-app avatar-xl'><i class='icon icon-config-outline'></i></div>";
                }
                elseif($right['icon'])
                {
                    echo "<div class='avatar avatar-app avatar-xl' data-code='$code'>" . html::image($right['icon']) . "</div>";
                }
                else
                {
                    $name = $right['abbr'] ? $right['abbr'] : $right['name'];
                    $rightName = validater::checkCode(substr($name, 0, 1)) ? strtoupper(substr($name, 0, 1)) : substr($name, 0, 3);
                    if(validater::checkCode(substr($name, 0, 1)) and validater::checkCode(substr($name, 1, 1)))   $rightName .= strtoupper(substr($name, 1, 1));
                    if(validater::checkCode(substr($name, 0, 1)) and !validater::checkCode(substr($name, 1, 1)))  $rightName .= strtoupper(substr($name, 1, 3));
                    if(!validater::checkCode(substr($name, 0, 1)) and validater::checkCode(substr($name, 3, 1)))  $rightName .= strtoupper(substr($name, 3, 1));
                    if(!validater::checkCode(substr($name, 0, 1)) and !validater::checkCode(substr($name, 3, 1))) $rightName .= substr($name, 3, 3);
                    echo "<div class='avatar avatar-app avatar-xl' data-code='$code' data-id='{$right['id']}' data-name='$rightName'></div>";
                }
                ?>
                <div class='app-name text-ellipsis'><?php echo $right['name']; ?></div>
                <input class='hidden' type='checkbox' name='apps[]' value='<?php echo $code; ?>' checked='checked' />
              </div>
            </div>
            <?php endif?>
            <?php endforeach?>
          </div>
        </div>
      </div>
    </div>
    <div class='form-tips text-warning text-center'><i class='icon icon-info'></i> <?php echo $lang->group->manageAppPrivTip; ?></div>
    <?php endif?>
    <?php if($type == 'byApp'):?>
    <div class='row'>
      <?php foreach($rights as $code => $right):?>
      <div class='col-xs-2'><?php echo html::checkbox('groups', array($code => $right['name']), $right['right'] == '1' ? $code : '');?></div>
      <?php endforeach?>
    </div>
    <?php endif?>
  </div>
  <div class='panel-footer form-actions text-center'>
    <?php
      echo html::submitButton();
      echo html::backButton();
      echo html::hidden('foo'); // Just a var, to make sure $_POST is not empty.
    ?>
  </div>
</form>
<?php include '../../common/view/footer.html.php';?>
